From d6988b473d06599b537b79de4a63f7e46d128403 Mon Sep 17 00:00:00 2001 From: Petka Antonov Date: Sun, 9 Feb 2014 11:20:13 +0200 Subject: [PATCH] Release v1.0.4 --- browser/bundle.js | 3146 ++++++++++++++++++++++++++++++++-------- js/browser/bluebird.js | 401 +++-- package.json | 2 +- 3 files changed, 2742 insertions(+), 807 deletions(-) diff --git a/browser/bundle.js b/browser/bundle.js index c8b5a56a4..dd2272fea 100644 --- a/browser/bundle.js +++ b/browser/bundle.js @@ -3254,7 +3254,7 @@ Promise.onPossiblyUnhandledRejection();(function (){ {fn: function(){ return require('../test/mocha/when_settle.js');}, name: '../test/mocha/when_settle.js'}, {fn: function(){ return require('../test/mocha/when_some.js');}, name: '../test/mocha/when_some.js'}, {fn: function(){ return require('../test/mocha/when_spread.js');}, name: '../test/mocha/when_spread.js'}]; -},{"../js/debug/bluebird.js":20,"../test/mocha/2.1.2.js":110,"../test/mocha/2.1.3.js":111,"../test/mocha/2.2.1.js":112,"../test/mocha/2.2.2.js":113,"../test/mocha/2.2.3.js":114,"../test/mocha/2.2.4.js":115,"../test/mocha/2.2.5.js":116,"../test/mocha/2.2.6.js":117,"../test/mocha/2.2.7.js":118,"../test/mocha/2.3.1.js":119,"../test/mocha/2.3.2.js":120,"../test/mocha/2.3.3.js":121,"../test/mocha/2.3.4.js":122,"../test/mocha/3.2.1.js":123,"../test/mocha/3.2.2.js":124,"../test/mocha/3.2.3.js":125,"../test/mocha/3.2.4.js":126,"../test/mocha/3.2.5.js":127,"../test/mocha/3.2.6.js":128,"../test/mocha/api_exceptions.js":129,"../test/mocha/async.js":130,"../test/mocha/bind.js":131,"../test/mocha/bluebird-debug-env-flag.js":132,"../test/mocha/bluebird-multiple-instances.js":133,"../test/mocha/cancel.js":134,"../test/mocha/catch_filter.js":135,"../test/mocha/collections_thenables.js":136,"../test/mocha/constructor.js":137,"../test/mocha/cycles.js":138,"../test/mocha/direct_resolving.js":139,"../test/mocha/error.js":140,"../test/mocha/filter.js":141,"../test/mocha/following.js":142,"../test/mocha/github36.js":143,"../test/mocha/late_buffer_safety.js":148,"../test/mocha/method.js":149,"../test/mocha/promisify.js":150,"../test/mocha/props.js":151,"../test/mocha/q_all.js":152,"../test/mocha/q_done.js":153,"../test/mocha/q_fin.js":154,"../test/mocha/q_inspect.js":155,"../test/mocha/q_make_node_resolver.js":156,"../test/mocha/q_nodeify.js":157,"../test/mocha/q_progress.js":158,"../test/mocha/q_propagation.js":159,"../test/mocha/q_settle.js":160,"../test/mocha/q_spread.js":161,"../test/mocha/race.js":162,"../test/mocha/reduce.js":163,"../test/mocha/resolution.js":164,"../test/mocha/reused_promise.js":165,"../test/mocha/some.js":166,"../test/mocha/sparsity.js":167,"../test/mocha/timers.js":168,"../test/mocha/try.js":169,"../test/mocha/unhandled_rejections.js":170,"../test/mocha/when_all.js":171,"../test/mocha/when_any.js":172,"../test/mocha/when_defer.js":173,"../test/mocha/when_join.js":174,"../test/mocha/when_map.js":175,"../test/mocha/when_reduce.js":176,"../test/mocha/when_settle.js":177,"../test/mocha/when_some.js":178,"../test/mocha/when_spread.js":179,"assert":2,"sinon":95}],17:[function(require,module,exports){ +},{"../js/debug/bluebird.js":20,"../test/mocha/2.1.2.js":111,"../test/mocha/2.1.3.js":112,"../test/mocha/2.2.1.js":113,"../test/mocha/2.2.2.js":114,"../test/mocha/2.2.3.js":115,"../test/mocha/2.2.4.js":116,"../test/mocha/2.2.5.js":117,"../test/mocha/2.2.6.js":118,"../test/mocha/2.2.7.js":119,"../test/mocha/2.3.1.js":120,"../test/mocha/2.3.2.js":121,"../test/mocha/2.3.3.js":122,"../test/mocha/2.3.4.js":123,"../test/mocha/3.2.1.js":124,"../test/mocha/3.2.2.js":125,"../test/mocha/3.2.3.js":126,"../test/mocha/3.2.4.js":127,"../test/mocha/3.2.5.js":128,"../test/mocha/3.2.6.js":129,"../test/mocha/api_exceptions.js":130,"../test/mocha/async.js":131,"../test/mocha/bind.js":132,"../test/mocha/bluebird-debug-env-flag.js":133,"../test/mocha/bluebird-multiple-instances.js":134,"../test/mocha/cancel.js":135,"../test/mocha/catch_filter.js":136,"../test/mocha/collections_thenables.js":137,"../test/mocha/constructor.js":138,"../test/mocha/cycles.js":139,"../test/mocha/direct_resolving.js":140,"../test/mocha/error.js":141,"../test/mocha/filter.js":142,"../test/mocha/following.js":143,"../test/mocha/github36.js":144,"../test/mocha/late_buffer_safety.js":149,"../test/mocha/method.js":150,"../test/mocha/promisify.js":151,"../test/mocha/props.js":152,"../test/mocha/q_all.js":153,"../test/mocha/q_done.js":154,"../test/mocha/q_fin.js":155,"../test/mocha/q_inspect.js":156,"../test/mocha/q_make_node_resolver.js":157,"../test/mocha/q_nodeify.js":158,"../test/mocha/q_progress.js":159,"../test/mocha/q_propagation.js":160,"../test/mocha/q_settle.js":161,"../test/mocha/q_spread.js":162,"../test/mocha/race.js":163,"../test/mocha/reduce.js":164,"../test/mocha/resolution.js":165,"../test/mocha/reused_promise.js":166,"../test/mocha/some.js":167,"../test/mocha/sparsity.js":168,"../test/mocha/timers.js":169,"../test/mocha/try.js":170,"../test/mocha/unhandled_rejections.js":171,"../test/mocha/when_all.js":172,"../test/mocha/when_any.js":173,"../test/mocha/when_defer.js":174,"../test/mocha/when_join.js":175,"../test/mocha/when_map.js":176,"../test/mocha/when_reduce.js":177,"../test/mocha/when_settle.js":178,"../test/mocha/when_some.js":179,"../test/mocha/when_spread.js":180,"assert":2,"sinon":96}],17:[function(require,module,exports){ /** * Copyright (c) 2014 Petka Antonov * @@ -3826,7 +3826,7 @@ var captureStackTrace = (function stackDetection() { typeof "".startsWith === "function" && (err.stack.startsWith("stackDetection@")) && stackDetection.name === "stackDetection") { - + defineProperty(Error, "stackTraceLimit", { writable: true, enumerable: false, @@ -3918,6 +3918,7 @@ return CapturedTrace; "use strict"; module.exports = function(NEXT_FILTER) { var util = require("./util.js"); +var errors = require("./errors.js"); var tryCatch1 = util.tryCatch1; var errorObj = util.errorObj; var keys = require("./es5.js").keys; @@ -3963,7 +3964,10 @@ CatchFilter.prototype.doFilter = function CatchFilter$_doFilter(e) { } else if (typeof item === "function" && !itemIsErrorType) { var shouldHandle = CatchFilter$_safePredicate(item, e); if (shouldHandle === errorObj) { - this._promise._attachExtraTrace(errorObj.e); + var trace = errors.canAttach(errorObj.e) + ? errorObj.e + : new Error(errorObj.e + ""); + this._promise._attachExtraTrace(trace); e = errorObj.e; break; } else if (shouldHandle) { @@ -3983,7 +3987,7 @@ CatchFilter.prototype.doFilter = function CatchFilter$_doFilter(e) { return CatchFilter; }; -},{"./es5.js":28,"./util.js":55}],25:[function(require,module,exports){ +},{"./errors.js":26,"./es5.js":28,"./util.js":55}],25:[function(require,module,exports){ /** * Copyright (c) 2014 Petka Antonov * @@ -4099,39 +4103,9 @@ var global = require("./global.js"); var Objectfreeze = require("./es5.js").freeze; var util = require("./util.js"); var inherits = util.inherits; -var isObject = util.isObject; var notEnumerableProp = util.notEnumerableProp; var Error = global.Error; -function isStackAttached(val) { - return (val & 1) > 0; -} - -function isHandled(val) { - return (val & 2) > 0; -} - -function withStackAttached(val) { - return (val | 1); -} - -function withHandledMarked(val) { - return (val | 2); -} - -function withHandledUnmarked(val) { - return (val & (~2)); -} - -function ensureNotHandled(reason) { - var field; - if (isObject(reason) && - ((field = reason["__promiseHandled__"]) !== void 0)) { - reason["__promiseHandled__"] = withHandledUnmarked(field); - } - return reason; -} - function markAsOriginatingFromRejection(e) { try { notEnumerableProp(e, "isAsync", true); @@ -4145,29 +4119,12 @@ function originatesFromRejection(e) { e["isAsync"] === true); } -function attachDefaultState(obj) { - try { - notEnumerableProp(obj, "__promiseHandled__", 0); - return true; - } - catch(e) { - return false; - } -} - function isError(obj) { return obj instanceof Error; } function canAttach(obj) { - if (isError(obj)) { - var handledState = obj["__promiseHandled__"]; - if (handledState === void 0) { - return attachDefaultState(obj); - } - return !isStackAttached(handledState); - } - return false; + return isError(obj); } function subError(nameProperty, defaultMessage) { @@ -4231,13 +4188,6 @@ module.exports = { TimeoutError: errorTypes.TimeoutError, originatesFromRejection: originatesFromRejection, markAsOriginatingFromRejection: markAsOriginatingFromRejection, - attachDefaultState: attachDefaultState, - ensureNotHandled: ensureNotHandled, - withHandledUnmarked: withHandledUnmarked, - withHandledMarked: withHandledMarked, - withStackAttached: withStackAttached, - isStackAttached: isStackAttached, - isHandled: isHandled, canAttach: canAttach }; @@ -4460,7 +4410,6 @@ module.exports = function(Promise) { */ module.exports = function(Promise, NEXT_FILTER) { var util = require("./util.js"); - var ensureNotHandled = require("./errors.js").ensureNotHandled; var wrapsPrimitiveReceiver = util.wrapsPrimitiveReceiver; var isPrimitive = util.isPrimitive; var thrower = util.thrower; @@ -4470,7 +4419,6 @@ module.exports = function(Promise, NEXT_FILTER) { return this; } function throwThis() { - ensureNotHandled(this); throw this; } function makeReturner(r) { @@ -4480,7 +4428,6 @@ module.exports = function(Promise, NEXT_FILTER) { } function makeThrower(r) { return function Promise$_thrower() { - ensureNotHandled(r); throw r; }; } @@ -4521,7 +4468,6 @@ module.exports = function(Promise, NEXT_FILTER) { } if (promise.isRejected()) { - ensureNotHandled(reasonOrValue); NEXT_FILTER.e = reasonOrValue; return NEXT_FILTER; } @@ -4544,7 +4490,7 @@ module.exports = function(Promise, NEXT_FILTER) { }; }; -},{"./errors.js":26,"./util.js":55}],31:[function(require,module,exports){ +},{"./util.js":55}],31:[function(require,module,exports){ /** * Copyright (c) 2014 Petka Antonov * @@ -4873,6 +4819,7 @@ module.exports = function(Promise, isPromiseArrayProxy) { var ASSERT = require("./assert.js"); var util = require("./util.js"); var async = require("./async.js"); + var errors = require("./errors.js"); var tryCatch1 = util.tryCatch1; var errorObj = util.errorObj; @@ -4917,11 +4864,10 @@ module.exports = function(Promise, isPromiseArrayProxy) { if (ret === errorObj) { if (ret.e != null && - ret.e.name === "StopProgressPropagation") { - ret.e["__promiseHandled__"] = 2; - } - else { - promise._attachExtraTrace(ret.e); + ret.e.name !== "StopProgressPropagation") { + var trace = errors.canAttach(ret.e) + ? ret.e : new Error(ret.e + ""); + promise._attachExtraTrace(trace); promise._progress(ret.e); } } @@ -4972,7 +4918,7 @@ module.exports = function(Promise, isPromiseArrayProxy) { }; }; -},{"./assert.js":18,"./async.js":19,"./util.js":55}],36:[function(require,module,exports){ +},{"./assert.js":18,"./async.js":19,"./errors.js":26,"./util.js":55}],36:[function(require,module,exports){ var process=require("__browserify_process");/** * Copyright (c) 2014 Petka Antonov * @@ -5013,10 +4959,7 @@ var CatchFilter = require("./catch_filter.js")(NEXT_FILTER); var PromiseResolver = require("./promise_resolver.js"); var isArray = util.isArray; -var notEnumerableProp = util.notEnumerableProp; -var isObject = util.isObject; -var ensurePropertyExpansion = util.ensurePropertyExpansion; var errorObj = util.errorObj; var tryCatch1 = util.tryCatch1; var tryCatch2 = util.tryCatch2; @@ -5028,11 +4971,6 @@ var TimeoutError = errors.TimeoutError; var RejectionError = errors.RejectionError; var originatesFromRejection = errors.originatesFromRejection; var markAsOriginatingFromRejection = errors.markAsOriginatingFromRejection; -var ensureNotHandled = errors.ensureNotHandled; -var withHandledMarked = errors.withHandledMarked; -var withStackAttached = errors.withStackAttached; -var isStackAttached = errors.isStackAttached; -var isHandled = errors.isHandled; var canAttach = errors.canAttach; var thrower = util.thrower; var apiRejection = require("./errors_api_rejection")(Promise); @@ -5234,6 +5172,10 @@ Promise.reject = Promise.rejected = function Promise$Reject(reason) { ret._cleanValues(); ret._setRejected(); ret._settledValue = reason; + if (!canAttach(reason)) { + var trace = new Error(reason + ""); + ret._setCarriedStackTrace(trace); + } return ret; }; @@ -5359,7 +5301,7 @@ Promise.prototype._setProxyHandlers = function Promise$_setProxyHandlers(receiver, promiseSlotValue) { var index = this._length(); - if (index >= 4194303 - 5) { + if (index >= 1048575 - 5) { index = 0; this._setLength(0); } @@ -5450,7 +5392,7 @@ Promise.prototype._length = function Promise$_length() { "isPromise(this)"); ASSERT((arguments.length === 0), "arguments.length === 0"); - return this._bitField & 4194303; + return this._bitField & 1048575; }; Promise.prototype._isFollowingOrFulfilledOrRejected = @@ -5463,12 +5405,8 @@ Promise.prototype._isFollowing = function Promise$_isFollowing() { }; Promise.prototype._setLength = function Promise$_setLength(len) { - this._bitField = (this._bitField & -4194304) | - (len & 4194303); -}; - -Promise.prototype._cancellable = function Promise$_cancellable() { - return (this._bitField & 67108864) > 0; + this._bitField = (this._bitField & -1048576) | + (len & 1048575); }; Promise.prototype._setFulfilled = function Promise$_setFulfilled() { @@ -5491,6 +5429,10 @@ Promise.prototype._isFinal = function Promise$_isFinal() { return (this._bitField & 33554432) > 0; }; +Promise.prototype._cancellable = function Promise$_cancellable() { + return (this._bitField & 67108864) > 0; +}; + Promise.prototype._setCancellable = function Promise$_setCancellable() { this._bitField = this._bitField | 67108864; }; @@ -5499,6 +5441,55 @@ Promise.prototype._unsetCancellable = function Promise$_unsetCancellable() { this._bitField = this._bitField & (~67108864); }; +Promise.prototype._setRejectionIsUnhandled = +function Promise$_setRejectionIsUnhandled() { + ASSERT(this.isRejected(), + "this.isRejected()"); + this._bitField = this._bitField | 2097152; +}; + +Promise.prototype._unsetRejectionIsUnhandled = +function Promise$_unsetRejectionIsUnhandled() { + ASSERT(this.isRejected(), + "this.isRejected()"); + this._bitField = this._bitField & (~2097152); +}; + +Promise.prototype._isRejectionUnhandled = +function Promise$_isRejectionUnhandled() { + return (this._bitField & 2097152) > 0; +}; + +Promise.prototype._setCarriedStackTrace = +function Promise$_setCarriedStackTrace(capturedTrace) { + ASSERT(this.isRejected(), + "this.isRejected()"); + this._bitField = this._bitField | 1048576; + this._fulfillmentHandler0 = capturedTrace; +}; + +Promise.prototype._unsetCarriedStackTrace = +function Promise$_unsetCarriedStackTrace() { + ASSERT(this.isRejected(), + "this.isRejected()"); + this._bitField = this._bitField & (~1048576); + this._fulfillmentHandler0 = void 0; +}; + +Promise.prototype._isCarryingStackTrace = +function Promise$_isCarryingStackTrace() { + return (this._bitField & 1048576) > 0; +}; + +Promise.prototype._getCarriedStackTrace = +function Promise$_getCarriedStackTrace() { + ASSERT(this.isRejected(), + "this.isRejected()"); + return this._isCarryingStackTrace() + ? this._fulfillmentHandler0 + : void 0; +}; + Promise.prototype._receiverAt = function Promise$_receiverAt(index) { ASSERT(((typeof index) === "number"), "typeof index === \u0022number\u0022"); @@ -5539,6 +5530,8 @@ function Promise$_fulfillmentHandlerAt(index) { "index >= 0"); ASSERT(((index % 5) === 0), "index % CALLBACK_SIZE === 0"); + ASSERT((! this._isCarryingStackTrace()), + "!this._isCarryingStackTrace()"); if (index === 0) return this._fulfillmentHandler0; return this[index + 0 - 5]; }; @@ -5563,11 +5556,13 @@ Promise.prototype._unsetAt = function Promise$_unsetAt(index) { ASSERT(((index % 5) === 0), "index % CALLBACK_SIZE === 0"); if (index === 0) { - this._fulfillmentHandler0 = this._rejectionHandler0 = this._progressHandler0 = this._promise0 = this._receiver0 = void 0; + if (!this._isCarryingStackTrace()) { + this._fulfillmentHandler0 = void 0; + } } else { this[index - 5 + 0] = @@ -5595,15 +5590,17 @@ function Promise$_resolveFromResolver(resolver) { promise._fulfill(val); } function Promise$_rejecter(val) { - promise._attachExtraTrace(val); + var trace = canAttach(val) ? val : new Error(val + ""); + promise._attachExtraTrace(trace); markAsOriginatingFromRejection(val); - promise._reject(val); + promise._reject(val, trace === val ? void 0 : trace); } var r = tryCatch2(resolver, void 0, Promise$_resolver, Promise$_rejecter); if (localDebugging) this._popContext(); if (r !== void 0 && r === errorObj) { - promise._reject(r.e); + var trace = canAttach(r.e) ? r.e : new Error(r.e + ""); + promise._reject(r.e, trace); } }; @@ -5616,7 +5613,7 @@ Promise.prototype._addCallbacks = function Promise$_addCallbacks( ) { var index = this._length(); - if (index >= 4194303 - 5) { + if (index >= 1048575 - 5) { index = 0; this._setLength(0); } @@ -5624,7 +5621,8 @@ Promise.prototype._addCallbacks = function Promise$_addCallbacks( if (index === 0) { this._promise0 = promise; if (receiver !== void 0) this._receiver0 = receiver; - if (typeof fulfill === "function") this._fulfillmentHandler0 = fulfill; + if (typeof fulfill === "function" && !this._isCarryingStackTrace()) + this._fulfillmentHandler0 = fulfill; if (typeof reject === "function") this._rejectionHandler0 = reject; if (typeof progress === "function") this._progressHandler0 = progress; } @@ -5679,21 +5677,6 @@ function Promise$_spreadSlowCase(targetFn, promise, values, boundTo) { promise._follow(promiseForAll); }; -Promise.prototype._markHandled = function Promise$_markHandled(value) { - if( typeof value === "object" && - value !== null) { - var handledState = value["__promiseHandled__"]; - - if (handledState === void 0) { - notEnumerableProp(value, "__promiseHandled__", 2); - } - else { - value["__promiseHandled__"] = - withHandledMarked(handledState); - } - } -}; - Promise.prototype._callSpread = function Promise$_callSpread(handler, promise, value, localDebugging) { var boundTo = this._isBound() ? this._boundTo : void 0; @@ -5733,7 +5716,7 @@ function Promise$_settlePromiseFromHandler( handler.call(receiver, value, promise); return; } - if (this.isRejected()) this._markHandled(value); + var localDebugging = debugging; var x = this._callHandler(handler, receiver, promise, value, localDebugging); @@ -5743,9 +5726,10 @@ function Promise$_settlePromiseFromHandler( if (x === errorObj || x === promise || x === NEXT_FILTER) { var err = x === promise ? makeSelfResolutionError() - : ensureNotHandled(x.e); - if (x !== NEXT_FILTER) promise._attachExtraTrace(err); - promise._rejectUnchecked(err); + : x.e; + var trace = canAttach(err) ? err : new Error(err + ""); + if (x !== NEXT_FILTER) promise._attachExtraTrace(trace); + promise._rejectUnchecked(err, trace); } else { var castValue = Promise._cast(x, @@ -5753,6 +5737,13 @@ function Promise$_settlePromiseFromHandler( promise); if (isPromise(castValue)) { + if (castValue.isRejected() && + !castValue._isCarryingStackTrace() && + !canAttach(castValue._settledValue)) { + var trace = new Error(castValue._settledValue + ""); + promise._attachExtraTrace(trace); + castValue._setCarriedStackTrace(trace); + } promise._follow(castValue); if (castValue._cancellable()) { promise._cancellationParent = castValue; @@ -5765,8 +5756,6 @@ function Promise$_settlePromiseFromHandler( } }; - - Promise.prototype._follow = function Promise$_follow(promise) { ASSERT((arguments.length === 1), @@ -5790,7 +5779,8 @@ function Promise$_follow(promise) { this._fulfillUnchecked(promise._settledValue); } else { - this._rejectUnchecked(promise._settledValue); + this._rejectUnchecked(promise._settledValue, + promise._getCarriedStackTrace()); } if (debugging && @@ -5855,8 +5845,9 @@ Promise.prototype._setTrace = function Promise$_setTrace(caller, parent) { Promise.prototype._attachExtraTrace = function Promise$_attachExtraTrace(error) { - if (debugging && - canAttach(error)) { + if (debugging) { + ASSERT(canAttach(error), + "canAttach(error)"); var promise = this; var stack = error.stack; stack = typeof stack === "string" @@ -5883,24 +5874,6 @@ function Promise$_attachExtraTrace(error) { else { error.stack = stack.join("\n"); } - error["__promiseHandled__"] = - withStackAttached(error["__promiseHandled__"]); - } -}; - -Promise.prototype._notifyUnhandledRejection = -function Promise$_notifyUnhandledRejection(reason) { - if (!isHandled(reason["__promiseHandled__"])) { - reason["__promiseHandled__"] = - withHandledMarked(reason["__promiseHandled__"]); - CapturedTrace.possiblyUnhandledRejection(reason, this); - } -}; - -Promise.prototype._unhandledRejection = -function Promise$_unhandledRejection(reason) { - if (!isHandled(reason["__promiseHandled__"])) { - async.invokeLater(this._notifyUnhandledRejection, this, reason); } }; @@ -5913,12 +5886,12 @@ Promise.prototype._cleanValues = function Promise$_cleanValues() { Promise.prototype._fulfill = function Promise$_fulfill(value) { if (this._isFollowingOrFulfilledOrRejected()) return; this._fulfillUnchecked(value); - }; -Promise.prototype._reject = function Promise$_reject(reason) { +Promise.prototype._reject = +function Promise$_reject(reason, carriedStackTrace) { if (this._isFollowingOrFulfilledOrRejected()) return; - this._rejectUnchecked(reason); + this._rejectUnchecked(reason, carriedStackTrace); }; Promise.prototype._settlePromiseAt = function Promise$_settlePromiseAt(index) { @@ -5947,8 +5920,8 @@ Promise.prototype._settlePromiseAt = function Promise$_settlePromiseAt(index) { receiver._unsetProxied(); if (isFulfilled) receiver._fulfillUnchecked(value); - else receiver._rejectUnchecked(value); - + else receiver._rejectUnchecked(value, + this._getCarriedStackTrace()); done = true; } else if (isPromiseArrayProxy(receiver, promise)) { @@ -5963,7 +5936,7 @@ Promise.prototype._settlePromiseAt = function Promise$_settlePromiseAt(index) { if (!done) { if (isFulfilled) promise._fulfill(value); - else promise._reject(value); + else promise._reject(value, this._getCarriedStackTrace()); } } @@ -6020,6 +5993,7 @@ Promise.prototype._queueSettleAt = function Promise$_queueSettleAt(index) { "index >= 0"); ASSERT((this.isFulfilled() || this.isRejected()), "this.isFulfilled() || this.isRejected()"); + if (this._isRejectionUnhandled()) this._unsetRejectionIsUnhandled(); async.invoke(this._settlePromiseAt, this, index); }; @@ -6029,7 +6003,7 @@ function Promise$_fulfillUnchecked(value) { if (value === this) { var err = makeSelfResolutionError(); this._attachExtraTrace(err); - return this._rejectUnchecked(err); + return this._rejectUnchecked(err, void 0); } this._cleanValues(); this._setFulfilled(); @@ -6041,17 +6015,14 @@ function Promise$_fulfillUnchecked(value) { } }; -Promise.prototype._fulfillPromises = function Promise$_fulfillPromises(len) { - ASSERT(this.isFulfilled(), - "this.isFulfilled()"); - len = this._length(); - for (var i = 0; i < len; i+= 5) { - this._settlePromiseAt(i); - } +Promise.prototype._rejectUncheckedCheckError = +function Promise$_rejectUncheckedCheckError(reason) { + var trace = canAttach(reason) ? reason : new Error(reason + ""); + this._rejectUnchecked(reason, trace === reason ? void 0 : trace); }; Promise.prototype._rejectUnchecked = -function Promise$_rejectUnchecked(reason) { +function Promise$_rejectUnchecked(reason, trace) { if (!this.isPending()) return; if (reason === this) { var err = makeSelfResolutionError(); @@ -6061,18 +6032,22 @@ function Promise$_rejectUnchecked(reason) { this._cleanValues(); this._setRejected(); this._settledValue = reason; + if (this._isFinal()) { ASSERT((this._length() === 0), "this._length() === 0"); - async.invokeLater(thrower, void 0, reason); + async.invokeLater(thrower, void 0, trace === void 0 ? reason : trace); return; } var len = this._length(); + + if (trace !== void 0) this._setCarriedStackTrace(trace); + if (len > 0) { async.invoke(this._rejectPromises, this, len); } else { - this._ensurePossibleRejectionHandled(reason); + this._ensurePossibleRejectionHandled(); } }; @@ -6080,54 +6055,42 @@ Promise.prototype._rejectPromises = function Promise$_rejectPromises(len) { ASSERT(this.isRejected(), "this.isRejected()"); len = this._length(); - var rejectionWasHandled = false; for (var i = 0; i < len; i+= 5) { - var handler = this._rejectionHandlerAt(i); - if (!rejectionWasHandled) { - if(typeof handler === "function") rejectionWasHandled = true; - else { - var promise = this._promiseAt(i); - if (isPromise(promise) && promise._length() > 0) { - rejectionWasHandled = true; - } - else { - var receiver = this._receiverAt(i); - if (isPromise(receiver) && receiver._length() > 0 || - isPromiseArrayProxy(receiver, promise)) { - rejectionWasHandled = true; - } - } - } - } this._settlePromiseAt(i); } + this._unsetCarriedStackTrace(); +}; - if (!rejectionWasHandled) { - this._ensurePossibleRejectionHandled(this._settledValue); +Promise.prototype._fulfillPromises = function Promise$_fulfillPromises(len) { + ASSERT(this.isFulfilled(), + "this.isFulfilled()"); + len = this._length(); + for (var i = 0; i < len; i+= 5) { + this._settlePromiseAt(i); } }; Promise.prototype._ensurePossibleRejectionHandled = -function Promise$_ensurePossibleRejectionHandled(reason) { +function Promise$_ensurePossibleRejectionHandled() { + this._setRejectionIsUnhandled(); if (CapturedTrace.possiblyUnhandledRejection !== void 0) { - if (isObject(reason)) { - var handledState = reason["__promiseHandled__"]; - var newReason = reason; + async.invokeLater(this._notifyUnhandledRejection, this, void 0); + } +}; - if (handledState === void 0) { - newReason = ensurePropertyExpansion(reason, - "__promiseHandled__", 0); - handledState = 0; - } - else if (isHandled(handledState)) { - return; - } +Promise.prototype._notifyUnhandledRejection = +function Promise$_notifyUnhandledRejection() { + if (this._isRejectionUnhandled()) { + var reason = this._settledValue; + var trace = this._getCarriedStackTrace(); - if (!isStackAttached(handledState)) { - this._attachExtraTrace(newReason); - } - async.invoke(this._unhandledRejection, this, newReason); + this._unsetRejectionIsUnhandled(); + + if (trace !== void 0) { + this._unsetCarriedStackTrace(); + reason = trace; } + CapturedTrace.possiblyUnhandledRejection(reason, this); } }; @@ -6257,7 +6220,7 @@ return Promise; "use strict"; module.exports = function(Promise, INTERNAL) { var ASSERT = require("./assert.js"); -var ensureNotHandled = require("./errors.js").ensureNotHandled; +var canAttach = require("./errors.js").canAttach; var util = require("./util.js"); var async = require("./async.js"); var hasOwn = {}.hasOwnProperty; @@ -6444,10 +6407,10 @@ PromiseArray.prototype.__hardReject__ = PromiseArray.prototype._reject = function PromiseArray$_reject(reason) { ASSERT((! this._isResolved()), "!this._isResolved()"); - ensureNotHandled(reason); this._values = null; - this._promise._attachExtraTrace(reason); - this._promise._reject(reason); + var trace = canAttach(reason) ? reason : new Error(reason + ""); + this._promise._attachExtraTrace(trace); + this._promise._reject(reason, trace); }; PromiseArray.prototype._promiseProgressed = @@ -6610,6 +6573,8 @@ function wrapAsRejectionError(obj) { function nodebackForPromise(promise) { function PromiseResolver$_callback(err, value) { + if (promise === null) return; + if (err) { var wrapped = wrapAsRejectionError(maybeWrapAsError(err)); promise._attachExtraTrace(wrapped); @@ -6624,6 +6589,8 @@ function nodebackForPromise(promise) { promise._fulfill(value); } } + + promise = null; } return PromiseResolver$_callback; } @@ -6670,8 +6637,12 @@ PromiseResolver.prototype.fulfill = function PromiseResolver$resolve(value) { PromiseResolver.prototype.reject = function PromiseResolver$reject(reason) { var promise = this.promise; errors.markAsOriginatingFromRejection(reason); - promise._attachExtraTrace(reason); + var trace = errors.canAttach(reason) ? reason : new Error(reason + ""); + promise._attachExtraTrace(trace); async.invoke(promise._reject, promise, reason); + if (trace !== reason) { + async.invoke(this._setCarriedStackTrace, this, trace); + } }; PromiseResolver.prototype.progress = @@ -6695,6 +6666,13 @@ PromiseResolver.prototype.toJSON = function PromiseResolver$toJSON() { return this.promise.toJSON(); }; +PromiseResolver.prototype._setCarriedStackTrace = +function PromiseResolver$_setCarriedStackTrace(trace) { + if (this.promise.isRejected()) { + this.promise._setCarriedStackTrace(trace); + } +}; + module.exports = PromiseResolver; },{"./async.js":19,"./errors.js":26,"./es5.js":28,"./util.js":55}],40:[function(require,module,exports){ @@ -6724,7 +6702,6 @@ module.exports = PromiseResolver; module.exports = function(Promise, INTERNAL) { var errors = require("./errors.js"); var TypeError = errors.TypeError; -var ensureNotHandled = errors.ensureNotHandled; var util = require("./util.js"); var isArray = util.isArray; var errorObj = util.errorObj; @@ -6752,8 +6729,10 @@ PromiseSpawn.prototype._run = function PromiseSpawn$_run() { PromiseSpawn.prototype._continue = function PromiseSpawn$_continue(result) { if (result === errorObj) { this._generator = void 0; - this._promise._attachExtraTrace(result.e); - this._promise._reject(result.e); + var trace = errors.canAttach(result.e) + ? result.e : new Error(result.e + ""); + this._promise._attachExtraTrace(trace); + this._promise._reject(result.e, trace); return; } @@ -6789,8 +6768,8 @@ PromiseSpawn.prototype._continue = function PromiseSpawn$_continue(result) { }; PromiseSpawn.prototype._throw = function PromiseSpawn$_throw(reason) { - ensureNotHandled(reason); - this._promise._attachExtraTrace(reason); + if (errors.canAttach(reason)) + this._promise._attachExtraTrace(reason); this._continue( tryCatch1(this._generator["throw"], this._generator, reason) ); @@ -8118,6 +8097,7 @@ module.exports = function(Promise) { module.exports = function(Promise, INTERNAL) { var ASSERT = require("./assert.js"); var util = require("./util.js"); + var canAttach = require("./errors.js").canAttach; var errorObj = util.errorObj; var isObject = util.isObject; @@ -8143,7 +8123,7 @@ module.exports = function(Promise, INTERNAL) { ret._setTrace(caller, void 0); obj._then( ret._fulfillUnchecked, - ret._rejectUnchecked, + ret._rejectUncheckedCheckError, ret._progressUnchecked, ret, null, @@ -8155,7 +8135,7 @@ module.exports = function(Promise, INTERNAL) { var then = getThen(obj); if (then === errorObj) { caller = typeof caller === "function" ? caller : Promise$_Cast; - if (originalPromise !== void 0) { + if (originalPromise !== void 0 && canAttach(then.e)) { originalPromise._attachExtraTrace(then.e); } return Promise.reject(then.e, caller); @@ -8191,10 +8171,11 @@ module.exports = function(Promise, INTERNAL) { catch(e) { if (!called) { called = true; + var trace = canAttach(e) ? e : new Error(e + ""); if (originalPromise !== void 0) { - originalPromise._attachExtraTrace(e); + originalPromise._attachExtraTrace(trace); } - resolver.promise._reject(e); + resolver.promise._reject(e, trace); } } return resolver.promise; @@ -8208,7 +8189,7 @@ module.exports = function(Promise, INTERNAL) { if (originalPromise !== void 0) { originalPromise._attachExtraTrace(e); } - resolver.promise._reject(e); + resolver.promise._reject(e, void 0); return; } resolver.resolve(y); @@ -8217,12 +8198,11 @@ module.exports = function(Promise, INTERNAL) { function Promise$_rejectFromThenable(r) { if (called) return; called = true; - + var trace = canAttach(r) ? r : new Error(r + ""); if (originalPromise !== void 0) { - originalPromise._attachExtraTrace(r); + originalPromise._attachExtraTrace(trace); } - resolver.promise._attachExtraTrace(r); - resolver.promise._reject(r); + resolver.promise._reject(r, trace); } function Promise$_progressFromThenable(v) { @@ -8237,7 +8217,7 @@ module.exports = function(Promise, INTERNAL) { Promise._cast = Promise$_Cast; }; -},{"./assert.js":18,"./util.js":55}],54:[function(require,module,exports){ +},{"./assert.js":18,"./errors.js":26,"./util.js":55}],54:[function(require,module,exports){ /** * Copyright (c) 2014 Petka Antonov * @@ -8397,28 +8377,6 @@ var haveGetters = (function(){ })(); -var ensurePropertyExpansion = function(obj, prop, value) { - try { - notEnumerableProp(obj, prop, value); - return obj; - } - catch (e) { - var ret = {}; - var keys = es5.keys(obj); - for (var i = 0, len = keys.length; i < len; ++i) { - try { - var key = keys[i]; - ret[key] = obj[key]; - } - catch (err) { - ret[key] = err; - } - } - notEnumerableProp(ret, prop, value); - return ret; - } -}; - var canEvaluate = (function() { if (typeof window !== "undefined" && window !== null && typeof window.document !== "undefined" && @@ -8553,7 +8511,6 @@ var ret = { notEnumerableProp: notEnumerableProp, isPrimitive: isPrimitive, isObject: isObject, - ensurePropertyExpansion: ensurePropertyExpansion, canEvaluate: canEvaluate, deprecated: deprecated, errorObj: errorObj, @@ -8987,7 +8944,7 @@ var captureStackTrace = (function stackDetection() { typeof "".startsWith === "function" && (err.stack.startsWith("stackDetection@")) && stackDetection.name === "stackDetection") { - + defineProperty(Error, "stackTraceLimit", { writable: true, enumerable: false, @@ -9053,7 +9010,7 @@ return CapturedTrace; },{"./assert.js":57,"./es5.js":67,"./util.js":94}],63:[function(require,module,exports){ arguments[4][24][0].apply(exports,arguments) -},{"./es5.js":67,"./util.js":94}],64:[function(require,module,exports){ +},{"./errors.js":65,"./es5.js":67,"./util.js":94}],64:[function(require,module,exports){ /** * Copyright (c) 2014 Petka Antonov * @@ -9203,7 +9160,7 @@ module.exports = function(Promise) { },{"./assert.js":57,"./util.js":94}],69:[function(require,module,exports){ arguments[4][30][0].apply(exports,arguments) -},{"./errors.js":65,"./util.js":94}],70:[function(require,module,exports){ +},{"./util.js":94}],70:[function(require,module,exports){ arguments[4][31][0].apply(exports,arguments) },{"./errors.js":65,"./promise_spawn.js":79}],71:[function(require,module,exports){ module.exports=require(32) @@ -9432,6 +9389,7 @@ module.exports = function(Promise, isPromiseArrayProxy) { var ASSERT = require("./assert.js"); var util = require("./util.js"); var async = require("./async.js"); + var errors = require("./errors.js"); var tryCatch1 = util.tryCatch1; var errorObj = util.errorObj; @@ -9465,11 +9423,10 @@ module.exports = function(Promise, isPromiseArrayProxy) { if (ret === errorObj) { if (ret.e != null && - ret.e.name === "StopProgressPropagation") { - ret.e["__promiseHandled__"] = 2; - } - else { - promise._attachExtraTrace(ret.e); + ret.e.name !== "StopProgressPropagation") { + var trace = errors.canAttach(ret.e) + ? ret.e : new Error(ret.e + ""); + promise._attachExtraTrace(trace); promise._progress(ret.e); } } @@ -9520,7 +9477,7 @@ module.exports = function(Promise, isPromiseArrayProxy) { }; }; -},{"./assert.js":57,"./async.js":58,"./util.js":94}],75:[function(require,module,exports){ +},{"./assert.js":57,"./async.js":58,"./errors.js":65,"./util.js":94}],75:[function(require,module,exports){ var process=require("__browserify_process");/** * Copyright (c) 2014 Petka Antonov * @@ -9561,10 +9518,7 @@ var CatchFilter = require("./catch_filter.js")(NEXT_FILTER); var PromiseResolver = require("./promise_resolver.js"); var isArray = util.isArray; -var notEnumerableProp = util.notEnumerableProp; -var isObject = util.isObject; -var ensurePropertyExpansion = util.ensurePropertyExpansion; var errorObj = util.errorObj; var tryCatch1 = util.tryCatch1; var tryCatch2 = util.tryCatch2; @@ -9576,11 +9530,6 @@ var TimeoutError = errors.TimeoutError; var RejectionError = errors.RejectionError; var originatesFromRejection = errors.originatesFromRejection; var markAsOriginatingFromRejection = errors.markAsOriginatingFromRejection; -var ensureNotHandled = errors.ensureNotHandled; -var withHandledMarked = errors.withHandledMarked; -var withStackAttached = errors.withStackAttached; -var isStackAttached = errors.isStackAttached; -var isHandled = errors.isHandled; var canAttach = errors.canAttach; var thrower = util.thrower; var apiRejection = require("./errors_api_rejection")(Promise); @@ -9778,6 +9727,10 @@ Promise.reject = Promise.rejected = function Promise$Reject(reason) { ret._cleanValues(); ret._setRejected(); ret._settledValue = reason; + if (!canAttach(reason)) { + var trace = new Error(reason + ""); + ret._setCarriedStackTrace(trace); + } return ret; }; @@ -9903,7 +9856,7 @@ Promise.prototype._setProxyHandlers = function Promise$_setProxyHandlers(receiver, promiseSlotValue) { var index = this._length(); - if (index >= 4194303 - 5) { + if (index >= 1048575 - 5) { index = 0; this._setLength(0); } @@ -9972,7 +9925,7 @@ function Promise$_then( }; Promise.prototype._length = function Promise$_length() { - return this._bitField & 4194303; + return this._bitField & 1048575; }; Promise.prototype._isFollowingOrFulfilledOrRejected = @@ -9985,12 +9938,8 @@ Promise.prototype._isFollowing = function Promise$_isFollowing() { }; Promise.prototype._setLength = function Promise$_setLength(len) { - this._bitField = (this._bitField & -4194304) | - (len & 4194303); -}; - -Promise.prototype._cancellable = function Promise$_cancellable() { - return (this._bitField & 67108864) > 0; + this._bitField = (this._bitField & -1048576) | + (len & 1048575); }; Promise.prototype._setFulfilled = function Promise$_setFulfilled() { @@ -10013,6 +9962,10 @@ Promise.prototype._isFinal = function Promise$_isFinal() { return (this._bitField & 33554432) > 0; }; +Promise.prototype._cancellable = function Promise$_cancellable() { + return (this._bitField & 67108864) > 0; +}; + Promise.prototype._setCancellable = function Promise$_setCancellable() { this._bitField = this._bitField | 67108864; }; @@ -10021,6 +9974,45 @@ Promise.prototype._unsetCancellable = function Promise$_unsetCancellable() { this._bitField = this._bitField & (~67108864); }; +Promise.prototype._setRejectionIsUnhandled = +function Promise$_setRejectionIsUnhandled() { + this._bitField = this._bitField | 2097152; +}; + +Promise.prototype._unsetRejectionIsUnhandled = +function Promise$_unsetRejectionIsUnhandled() { + this._bitField = this._bitField & (~2097152); +}; + +Promise.prototype._isRejectionUnhandled = +function Promise$_isRejectionUnhandled() { + return (this._bitField & 2097152) > 0; +}; + +Promise.prototype._setCarriedStackTrace = +function Promise$_setCarriedStackTrace(capturedTrace) { + this._bitField = this._bitField | 1048576; + this._fulfillmentHandler0 = capturedTrace; +}; + +Promise.prototype._unsetCarriedStackTrace = +function Promise$_unsetCarriedStackTrace() { + this._bitField = this._bitField & (~1048576); + this._fulfillmentHandler0 = void 0; +}; + +Promise.prototype._isCarryingStackTrace = +function Promise$_isCarryingStackTrace() { + return (this._bitField & 1048576) > 0; +}; + +Promise.prototype._getCarriedStackTrace = +function Promise$_getCarriedStackTrace() { + return this._isCarryingStackTrace() + ? this._fulfillmentHandler0 + : void 0; +}; + Promise.prototype._receiverAt = function Promise$_receiverAt(index) { var ret; if (index === 0) { @@ -10054,11 +10046,13 @@ function Promise$_rejectionHandlerAt(index) { Promise.prototype._unsetAt = function Promise$_unsetAt(index) { if (index === 0) { - this._fulfillmentHandler0 = this._rejectionHandler0 = this._progressHandler0 = this._promise0 = this._receiver0 = void 0; + if (!this._isCarryingStackTrace()) { + this._fulfillmentHandler0 = void 0; + } } else { this[index - 5 + 0] = @@ -10084,15 +10078,17 @@ function Promise$_resolveFromResolver(resolver) { promise._fulfill(val); } function Promise$_rejecter(val) { - promise._attachExtraTrace(val); + var trace = canAttach(val) ? val : new Error(val + ""); + promise._attachExtraTrace(trace); markAsOriginatingFromRejection(val); - promise._reject(val); + promise._reject(val, trace === val ? void 0 : trace); } var r = tryCatch2(resolver, void 0, Promise$_resolver, Promise$_rejecter); if (localDebugging) this._popContext(); if (r !== void 0 && r === errorObj) { - promise._reject(r.e); + var trace = canAttach(r.e) ? r.e : new Error(r.e + ""); + promise._reject(r.e, trace); } }; @@ -10105,7 +10101,7 @@ Promise.prototype._addCallbacks = function Promise$_addCallbacks( ) { var index = this._length(); - if (index >= 4194303 - 5) { + if (index >= 1048575 - 5) { index = 0; this._setLength(0); } @@ -10113,7 +10109,8 @@ Promise.prototype._addCallbacks = function Promise$_addCallbacks( if (index === 0) { this._promise0 = promise; if (receiver !== void 0) this._receiver0 = receiver; - if (typeof fulfill === "function") this._fulfillmentHandler0 = fulfill; + if (typeof fulfill === "function" && !this._isCarryingStackTrace()) + this._fulfillmentHandler0 = fulfill; if (typeof reject === "function") this._rejectionHandler0 = reject; if (typeof progress === "function") this._progressHandler0 = progress; } @@ -10161,21 +10158,6 @@ function Promise$_spreadSlowCase(targetFn, promise, values, boundTo) { promise._follow(promiseForAll); }; -Promise.prototype._markHandled = function Promise$_markHandled(value) { - if( typeof value === "object" && - value !== null) { - var handledState = value["__promiseHandled__"]; - - if (handledState === void 0) { - notEnumerableProp(value, "__promiseHandled__", 2); - } - else { - value["__promiseHandled__"] = - withHandledMarked(handledState); - } - } -}; - Promise.prototype._callSpread = function Promise$_callSpread(handler, promise, value, localDebugging) { var boundTo = this._isBound() ? this._boundTo : void 0; @@ -10215,7 +10197,7 @@ function Promise$_settlePromiseFromHandler( handler.call(receiver, value, promise); return; } - if (this.isRejected()) this._markHandled(value); + var localDebugging = debugging; var x = this._callHandler(handler, receiver, promise, value, localDebugging); @@ -10225,9 +10207,10 @@ function Promise$_settlePromiseFromHandler( if (x === errorObj || x === promise || x === NEXT_FILTER) { var err = x === promise ? makeSelfResolutionError() - : ensureNotHandled(x.e); - if (x !== NEXT_FILTER) promise._attachExtraTrace(err); - promise._rejectUnchecked(err); + : x.e; + var trace = canAttach(err) ? err : new Error(err + ""); + if (x !== NEXT_FILTER) promise._attachExtraTrace(trace); + promise._rejectUnchecked(err, trace); } else { var castValue = Promise._cast(x, @@ -10235,6 +10218,13 @@ function Promise$_settlePromiseFromHandler( promise); if (isPromise(castValue)) { + if (castValue.isRejected() && + !castValue._isCarryingStackTrace() && + !canAttach(castValue._settledValue)) { + var trace = new Error(castValue._settledValue + ""); + promise._attachExtraTrace(trace); + castValue._setCarriedStackTrace(trace); + } promise._follow(castValue); if (castValue._cancellable()) { promise._cancellationParent = castValue; @@ -10247,8 +10237,6 @@ function Promise$_settlePromiseFromHandler( } }; - - Promise.prototype._follow = function Promise$_follow(promise) { this._setFollowing(); @@ -10264,7 +10252,8 @@ function Promise$_follow(promise) { this._fulfillUnchecked(promise._settledValue); } else { - this._rejectUnchecked(promise._settledValue); + this._rejectUnchecked(promise._settledValue, + promise._getCarriedStackTrace()); } if (debugging && @@ -10323,8 +10312,7 @@ Promise.prototype._setTrace = function Promise$_setTrace(caller, parent) { Promise.prototype._attachExtraTrace = function Promise$_attachExtraTrace(error) { - if (debugging && - canAttach(error)) { + if (debugging) { var promise = this; var stack = error.stack; stack = typeof stack === "string" @@ -10351,24 +10339,6 @@ function Promise$_attachExtraTrace(error) { else { error.stack = stack.join("\n"); } - error["__promiseHandled__"] = - withStackAttached(error["__promiseHandled__"]); - } -}; - -Promise.prototype._notifyUnhandledRejection = -function Promise$_notifyUnhandledRejection(reason) { - if (!isHandled(reason["__promiseHandled__"])) { - reason["__promiseHandled__"] = - withHandledMarked(reason["__promiseHandled__"]); - CapturedTrace.possiblyUnhandledRejection(reason, this); - } -}; - -Promise.prototype._unhandledRejection = -function Promise$_unhandledRejection(reason) { - if (!isHandled(reason["__promiseHandled__"])) { - async.invokeLater(this._notifyUnhandledRejection, this, reason); } }; @@ -10381,12 +10351,12 @@ Promise.prototype._cleanValues = function Promise$_cleanValues() { Promise.prototype._fulfill = function Promise$_fulfill(value) { if (this._isFollowingOrFulfilledOrRejected()) return; this._fulfillUnchecked(value); - }; -Promise.prototype._reject = function Promise$_reject(reason) { +Promise.prototype._reject = +function Promise$_reject(reason, carriedStackTrace) { if (this._isFollowingOrFulfilledOrRejected()) return; - this._rejectUnchecked(reason); + this._rejectUnchecked(reason, carriedStackTrace); }; Promise.prototype._settlePromiseAt = function Promise$_settlePromiseAt(index) { @@ -10410,8 +10380,8 @@ Promise.prototype._settlePromiseAt = function Promise$_settlePromiseAt(index) { receiver._unsetProxied(); if (isFulfilled) receiver._fulfillUnchecked(value); - else receiver._rejectUnchecked(value); - + else receiver._rejectUnchecked(value, + this._getCarriedStackTrace()); done = true; } else if (isPromiseArrayProxy(receiver, promise)) { @@ -10426,7 +10396,7 @@ Promise.prototype._settlePromiseAt = function Promise$_settlePromiseAt(index) { if (!done) { if (isFulfilled) promise._fulfill(value); - else promise._reject(value); + else promise._reject(value, this._getCarriedStackTrace()); } } @@ -10477,6 +10447,7 @@ Promise.prototype._gc = function Promise$gc() { }; Promise.prototype._queueSettleAt = function Promise$_queueSettleAt(index) { + if (this._isRejectionUnhandled()) this._unsetRejectionIsUnhandled(); async.invoke(this._settlePromiseAt, this, index); }; @@ -10486,7 +10457,7 @@ function Promise$_fulfillUnchecked(value) { if (value === this) { var err = makeSelfResolutionError(); this._attachExtraTrace(err); - return this._rejectUnchecked(err); + return this._rejectUnchecked(err, void 0); } this._cleanValues(); this._setFulfilled(); @@ -10498,15 +10469,14 @@ function Promise$_fulfillUnchecked(value) { } }; -Promise.prototype._fulfillPromises = function Promise$_fulfillPromises(len) { - len = this._length(); - for (var i = 0; i < len; i+= 5) { - this._settlePromiseAt(i); - } +Promise.prototype._rejectUncheckedCheckError = +function Promise$_rejectUncheckedCheckError(reason) { + var trace = canAttach(reason) ? reason : new Error(reason + ""); + this._rejectUnchecked(reason, trace === reason ? void 0 : trace); }; Promise.prototype._rejectUnchecked = -function Promise$_rejectUnchecked(reason) { +function Promise$_rejectUnchecked(reason, trace) { if (!this.isPending()) return; if (reason === this) { var err = makeSelfResolutionError(); @@ -10516,69 +10486,59 @@ function Promise$_rejectUnchecked(reason) { this._cleanValues(); this._setRejected(); this._settledValue = reason; + if (this._isFinal()) { - async.invokeLater(thrower, void 0, reason); + async.invokeLater(thrower, void 0, trace === void 0 ? reason : trace); return; } var len = this._length(); + + if (trace !== void 0) this._setCarriedStackTrace(trace); + if (len > 0) { async.invoke(this._rejectPromises, this, len); } else { - this._ensurePossibleRejectionHandled(reason); + this._ensurePossibleRejectionHandled(); } }; Promise.prototype._rejectPromises = function Promise$_rejectPromises(len) { len = this._length(); - var rejectionWasHandled = false; for (var i = 0; i < len; i+= 5) { - var handler = this._rejectionHandlerAt(i); - if (!rejectionWasHandled) { - if(typeof handler === "function") rejectionWasHandled = true; - else { - var promise = this._promiseAt(i); - if (isPromise(promise) && promise._length() > 0) { - rejectionWasHandled = true; - } - else { - var receiver = this._receiverAt(i); - if (isPromise(receiver) && receiver._length() > 0 || - isPromiseArrayProxy(receiver, promise)) { - rejectionWasHandled = true; - } - } - } - } this._settlePromiseAt(i); } + this._unsetCarriedStackTrace(); +}; - if (!rejectionWasHandled) { - this._ensurePossibleRejectionHandled(this._settledValue); +Promise.prototype._fulfillPromises = function Promise$_fulfillPromises(len) { + len = this._length(); + for (var i = 0; i < len; i+= 5) { + this._settlePromiseAt(i); } }; Promise.prototype._ensurePossibleRejectionHandled = -function Promise$_ensurePossibleRejectionHandled(reason) { +function Promise$_ensurePossibleRejectionHandled() { + this._setRejectionIsUnhandled(); if (CapturedTrace.possiblyUnhandledRejection !== void 0) { - if (isObject(reason)) { - var handledState = reason["__promiseHandled__"]; - var newReason = reason; + async.invokeLater(this._notifyUnhandledRejection, this, void 0); + } +}; - if (handledState === void 0) { - newReason = ensurePropertyExpansion(reason, - "__promiseHandled__", 0); - handledState = 0; - } - else if (isHandled(handledState)) { - return; - } +Promise.prototype._notifyUnhandledRejection = +function Promise$_notifyUnhandledRejection() { + if (this._isRejectionUnhandled()) { + var reason = this._settledValue; + var trace = this._getCarriedStackTrace(); - if (!isStackAttached(handledState)) { - this._attachExtraTrace(newReason); - } - async.invoke(this._unhandledRejection, this, newReason); + this._unsetRejectionIsUnhandled(); + + if (trace !== void 0) { + this._unsetCarriedStackTrace(); + reason = trace; } + CapturedTrace.possiblyUnhandledRejection(reason, this); } }; @@ -10703,7 +10663,7 @@ return Promise; "use strict"; module.exports = function(Promise, INTERNAL) { var ASSERT = require("./assert.js"); -var ensureNotHandled = require("./errors.js").ensureNotHandled; +var canAttach = require("./errors.js").canAttach; var util = require("./util.js"); var async = require("./async.js"); var hasOwn = {}.hasOwnProperty; @@ -10872,10 +10832,10 @@ PromiseArray.prototype._resolve = function PromiseArray$_resolve(value) { PromiseArray.prototype.__hardReject__ = PromiseArray.prototype._reject = function PromiseArray$_reject(reason) { - ensureNotHandled(reason); this._values = null; - this._promise._attachExtraTrace(reason); - this._promise._reject(reason); + var trace = canAttach(reason) ? reason : new Error(reason + ""); + this._promise._attachExtraTrace(trace); + this._promise._reject(reason, trace); }; PromiseArray.prototype._promiseProgressed = @@ -11833,6 +11793,7 @@ arguments[4][52][0].apply(exports,arguments) module.exports = function(Promise, INTERNAL) { var ASSERT = require("./assert.js"); var util = require("./util.js"); + var canAttach = require("./errors.js").canAttach; var errorObj = util.errorObj; var isObject = util.isObject; @@ -11856,7 +11817,7 @@ module.exports = function(Promise, INTERNAL) { ret._setTrace(caller, void 0); obj._then( ret._fulfillUnchecked, - ret._rejectUnchecked, + ret._rejectUncheckedCheckError, ret._progressUnchecked, ret, null, @@ -11868,7 +11829,7 @@ module.exports = function(Promise, INTERNAL) { var then = getThen(obj); if (then === errorObj) { caller = typeof caller === "function" ? caller : Promise$_Cast; - if (originalPromise !== void 0) { + if (originalPromise !== void 0 && canAttach(then.e)) { originalPromise._attachExtraTrace(then.e); } return Promise.reject(then.e, caller); @@ -11900,10 +11861,11 @@ module.exports = function(Promise, INTERNAL) { catch(e) { if (!called) { called = true; + var trace = canAttach(e) ? e : new Error(e + ""); if (originalPromise !== void 0) { - originalPromise._attachExtraTrace(e); + originalPromise._attachExtraTrace(trace); } - resolver.promise._reject(e); + resolver.promise._reject(e, trace); } } return resolver.promise; @@ -11917,7 +11879,7 @@ module.exports = function(Promise, INTERNAL) { if (originalPromise !== void 0) { originalPromise._attachExtraTrace(e); } - resolver.promise._reject(e); + resolver.promise._reject(e, void 0); return; } resolver.resolve(y); @@ -11926,12 +11888,11 @@ module.exports = function(Promise, INTERNAL) { function Promise$_rejectFromThenable(r) { if (called) return; called = true; - + var trace = canAttach(r) ? r : new Error(r + ""); if (originalPromise !== void 0) { - originalPromise._attachExtraTrace(r); + originalPromise._attachExtraTrace(trace); } - resolver.promise._attachExtraTrace(r); - resolver.promise._reject(r); + resolver.promise._reject(r, trace); } function Promise$_progressFromThenable(v) { @@ -11946,7 +11907,7 @@ module.exports = function(Promise, INTERNAL) { Promise._cast = Promise$_Cast; }; -},{"./assert.js":57,"./util.js":94}],93:[function(require,module,exports){ +},{"./assert.js":57,"./errors.js":65,"./util.js":94}],93:[function(require,module,exports){ arguments[4][54][0].apply(exports,arguments) },{"./assert.js":57,"./errors.js":65,"./errors_api_rejection":66,"./global.js":71,"./util.js":94}],94:[function(require,module,exports){ /** @@ -11991,28 +11952,6 @@ var haveGetters = (function(){ })(); -var ensurePropertyExpansion = function(obj, prop, value) { - try { - notEnumerableProp(obj, prop, value); - return obj; - } - catch (e) { - var ret = {}; - var keys = es5.keys(obj); - for (var i = 0, len = keys.length; i < len; ++i) { - try { - var key = keys[i]; - ret[key] = obj[key]; - } - catch (err) { - ret[key] = err; - } - } - notEnumerableProp(ret, prop, value); - return ret; - } -}; - var canEvaluate = (function() { if (typeof window !== "undefined" && window !== null && typeof window.document !== "undefined" && @@ -12095,69 +12034,2007 @@ function isObject(value) { return !isPrimitive(value); } -function maybeWrapAsError(maybeError) { - if (!isPrimitive(maybeError)) return maybeError; +function maybeWrapAsError(maybeError) { + if (!isPrimitive(maybeError)) return maybeError; + + return new Error(asString(maybeError)); +} + +function withAppended(target, appendee) { + var len = target.length; + var ret = new Array(len + 1); + var i; + for (i = 0; i < len; ++i) { + ret[i] = target[i]; + } + ret[i] = appendee; + return ret; +} + + +function notEnumerableProp(obj, name, value) { + var descriptor = { + value: value, + configurable: true, + enumerable: false, + writable: true + }; + es5.defineProperty(obj, name, descriptor); + return obj; +} + + +var wrapsPrimitiveReceiver = (function() { + return this !== "string"; +}).call("string"); + +function thrower(r) { + throw r; +} + + +var ret = { + thrower: thrower, + isArray: es5.isArray, + haveGetters: haveGetters, + notEnumerableProp: notEnumerableProp, + isPrimitive: isPrimitive, + isObject: isObject, + canEvaluate: canEvaluate, + deprecated: deprecated, + errorObj: errorObj, + tryCatch1: tryCatch1, + tryCatch2: tryCatch2, + tryCatchApply: tryCatchApply, + inherits: inherits, + withAppended: withAppended, + asString: asString, + maybeWrapAsError: maybeWrapAsError, + wrapsPrimitiveReceiver: wrapsPrimitiveReceiver +}; + +module.exports = ret; + +},{"./assert.js":57,"./es5.js":67,"./global.js":71}],95:[function(require,module,exports){ +var process=require("__browserify_process");// vim:ts=4:sts=4:sw=4: +/*! + * + * Copyright 2009-2012 Kris Kowal under the terms of the MIT + * license found at http://github.com/kriskowal/q/raw/master/LICENSE + * + * With parts by Tyler Close + * Copyright 2007-2009 Tyler Close under the terms of the MIT X license found + * at http://www.opensource.org/licenses/mit-license.html + * Forked at ref_send.js version: 2009-05-11 + * + * With parts by Mark Miller + * Copyright (C) 2011 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +(function (definition) { + // Turn off strict mode for this function so we can assign to global.Q + /* jshint strict: false */ + + // This file will function properly as a