diff --git a/browser/bundle.js b/browser/bundle.js index 33e88b281..272c68150 100644 --- a/browser/bundle.js +++ b/browser/bundle.js @@ -3258,7 +3258,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":21,"../test/mocha/2.1.2.js":73,"../test/mocha/2.1.3.js":74,"../test/mocha/2.2.1.js":75,"../test/mocha/2.2.2.js":76,"../test/mocha/2.2.3.js":77,"../test/mocha/2.2.4.js":78,"../test/mocha/2.2.5.js":79,"../test/mocha/2.2.6.js":80,"../test/mocha/2.2.7.js":81,"../test/mocha/2.3.1.js":82,"../test/mocha/2.3.2.js":83,"../test/mocha/2.3.3.js":84,"../test/mocha/2.3.4.js":85,"../test/mocha/3.2.1.js":86,"../test/mocha/3.2.2.js":87,"../test/mocha/3.2.3.js":88,"../test/mocha/3.2.4.js":89,"../test/mocha/3.2.5.js":90,"../test/mocha/3.2.6.js":91,"../test/mocha/api_exceptions.js":92,"../test/mocha/async.js":93,"../test/mocha/bind.js":94,"../test/mocha/bluebird-multiple-instances.js":95,"../test/mocha/cancel.js":96,"../test/mocha/catch_filter.js":97,"../test/mocha/collections_thenables.js":98,"../test/mocha/constructor.js":99,"../test/mocha/cycles.js":100,"../test/mocha/direct_resolving.js":101,"../test/mocha/domain.js":102,"../test/mocha/error.js":103,"../test/mocha/filter.js":104,"../test/mocha/following.js":105,"../test/mocha/github36.js":106,"../test/mocha/late_buffer_safety.js":111,"../test/mocha/method.js":112,"../test/mocha/promisify.js":113,"../test/mocha/props.js":114,"../test/mocha/q_all.js":115,"../test/mocha/q_done.js":116,"../test/mocha/q_fin.js":117,"../test/mocha/q_inspect.js":118,"../test/mocha/q_make_node_resolver.js":119,"../test/mocha/q_nodeify.js":120,"../test/mocha/q_progress.js":121,"../test/mocha/q_propagation.js":122,"../test/mocha/q_settle.js":123,"../test/mocha/q_spread.js":124,"../test/mocha/race.js":125,"../test/mocha/reduce.js":126,"../test/mocha/resolution.js":127,"../test/mocha/reused_promise.js":128,"../test/mocha/schedule.js":129,"../test/mocha/some.js":130,"../test/mocha/sparsity.js":131,"../test/mocha/tap.js":132,"../test/mocha/timers.js":133,"../test/mocha/try.js":134,"../test/mocha/unhandled_rejections.js":135,"../test/mocha/when_all.js":136,"../test/mocha/when_any.js":137,"../test/mocha/when_defer.js":138,"../test/mocha/when_join.js":139,"../test/mocha/when_map.js":140,"../test/mocha/when_reduce.js":141,"../test/mocha/when_settle.js":142,"../test/mocha/when_some.js":143,"../test/mocha/when_spread.js":144,"assert":2,"sinon":58}],18:[function(require,module,exports){ +},{"../js/debug/bluebird.js":21,"../test/mocha/2.1.2.js":72,"../test/mocha/2.1.3.js":73,"../test/mocha/2.2.1.js":74,"../test/mocha/2.2.2.js":75,"../test/mocha/2.2.3.js":76,"../test/mocha/2.2.4.js":77,"../test/mocha/2.2.5.js":78,"../test/mocha/2.2.6.js":79,"../test/mocha/2.2.7.js":80,"../test/mocha/2.3.1.js":81,"../test/mocha/2.3.2.js":82,"../test/mocha/2.3.3.js":83,"../test/mocha/2.3.4.js":84,"../test/mocha/3.2.1.js":85,"../test/mocha/3.2.2.js":86,"../test/mocha/3.2.3.js":87,"../test/mocha/3.2.4.js":88,"../test/mocha/3.2.5.js":89,"../test/mocha/3.2.6.js":90,"../test/mocha/api_exceptions.js":91,"../test/mocha/async.js":92,"../test/mocha/bind.js":93,"../test/mocha/bluebird-multiple-instances.js":94,"../test/mocha/cancel.js":95,"../test/mocha/catch_filter.js":96,"../test/mocha/collections_thenables.js":97,"../test/mocha/constructor.js":98,"../test/mocha/cycles.js":99,"../test/mocha/direct_resolving.js":100,"../test/mocha/domain.js":101,"../test/mocha/error.js":102,"../test/mocha/filter.js":103,"../test/mocha/following.js":104,"../test/mocha/github36.js":105,"../test/mocha/late_buffer_safety.js":110,"../test/mocha/method.js":111,"../test/mocha/promisify.js":112,"../test/mocha/props.js":113,"../test/mocha/q_all.js":114,"../test/mocha/q_done.js":115,"../test/mocha/q_fin.js":116,"../test/mocha/q_inspect.js":117,"../test/mocha/q_make_node_resolver.js":118,"../test/mocha/q_nodeify.js":119,"../test/mocha/q_progress.js":120,"../test/mocha/q_propagation.js":121,"../test/mocha/q_settle.js":122,"../test/mocha/q_spread.js":123,"../test/mocha/race.js":124,"../test/mocha/reduce.js":125,"../test/mocha/resolution.js":126,"../test/mocha/reused_promise.js":127,"../test/mocha/schedule.js":128,"../test/mocha/some.js":129,"../test/mocha/sparsity.js":130,"../test/mocha/tap.js":131,"../test/mocha/timers.js":132,"../test/mocha/try.js":133,"../test/mocha/unhandled_rejections.js":134,"../test/mocha/when_all.js":135,"../test/mocha/when_any.js":136,"../test/mocha/when_defer.js":137,"../test/mocha/when_join.js":138,"../test/mocha/when_map.js":139,"../test/mocha/when_reduce.js":140,"../test/mocha/when_settle.js":141,"../test/mocha/when_some.js":142,"../test/mocha/when_spread.js":143,"assert":2,"sinon":57}],18:[function(require,module,exports){ /** * Copyright (c) 2014 Petka Antonov * @@ -3284,41 +3284,40 @@ Promise.onPossiblyUnhandledRejection();(function (){ "use strict"; module.exports = function(Promise, Promise$_CreatePromiseArray, PromiseArray) { - var SomePromiseArray = require("./some_promise_array.js")(PromiseArray); - var ASSERT = require("./assert.js"); +var SomePromiseArray = require("./some_promise_array.js")(PromiseArray); +var ASSERT = require("./assert.js"); - function Promise$_Any(promises, useBound, caller) { - var ret = Promise$_CreatePromiseArray( - promises, - SomePromiseArray, - caller, - useBound === true && promises._isBound() - ? promises._boundTo - : void 0 - ); - var promise = ret.promise(); - if (promise.isRejected()) { - return promise; - } - ASSERT((ret instanceof SomePromiseArray), - "ret instanceof SomePromiseArray"); - ret.setHowMany(1); - ret.setUnwrap(); - ret.init(); +function Promise$_Any(promises, useBound) { + var ret = Promise$_CreatePromiseArray( + promises, + SomePromiseArray, + useBound === true && promises._isBound() + ? promises._boundTo + : void 0 + ); + var promise = ret.promise(); + if (promise.isRejected()) { return promise; } + ASSERT((ret instanceof SomePromiseArray), + "ret instanceof SomePromiseArray"); + ret.setHowMany(1); + ret.setUnwrap(); + ret.init(); + return promise; +} - Promise.any = function Promise$Any(promises) { - return Promise$_Any(promises, false, Promise.any); - }; +Promise.any = function Promise$Any(promises) { + return Promise$_Any(promises, false); +}; - Promise.prototype.any = function Promise$any() { - return Promise$_Any(this, true, this.any); - }; +Promise.prototype.any = function Promise$any() { + return Promise$_Any(this, true); +}; }; -},{"./assert.js":19,"./some_promise_array.js":52}],19:[function(require,module,exports){ +},{"./assert.js":19,"./some_promise_array.js":51}],19:[function(require,module,exports){ /** * Copyright (c) 2014 Petka Antonov * @@ -3343,64 +3342,64 @@ module.exports = function(Promise, Promise$_CreatePromiseArray, PromiseArray) { */ "use strict"; module.exports = (function(){ - var AssertionError = (function() { - function AssertionError(a) { - this.constructor$(a); - this.message = a; - this.name = "AssertionError"; - } - AssertionError.prototype = new Error(); - AssertionError.prototype.constructor = AssertionError; - AssertionError.prototype.constructor$ = Error; - return AssertionError; - })(); +var AssertionError = (function() { + function AssertionError(a) { + this.constructor$(a); + this.message = a; + this.name = "AssertionError"; + } + AssertionError.prototype = new Error(); + AssertionError.prototype.constructor = AssertionError; + AssertionError.prototype.constructor$ = Error; + return AssertionError; +})(); - function getParams(args) { - var params = []; - for (var i = 0; i < args.length; ++i) params.push("arg" + i); - return params; - } +function getParams(args) { + var params = []; + for (var i = 0; i < args.length; ++i) params.push("arg" + i); + return params; +} - function nativeAssert(callName, args, expect) { - try { - var params = getParams(args); - var constructorArgs = params; - constructorArgs.push("return " + - callName + "("+ params.join(",") + ");"); - var fn = Function.apply(null, constructorArgs); - return fn.apply(null, args); +function nativeAssert(callName, args, expect) { + try { + var params = getParams(args); + var constructorArgs = params; + constructorArgs.push("return " + + callName + "("+ params.join(",") + ");"); + var fn = Function.apply(null, constructorArgs); + return fn.apply(null, args); + } + catch (e) { + if (!(e instanceof SyntaxError)) { + throw e; } - catch (e) { - if (!(e instanceof SyntaxError)) { - throw e; - } - else { - return expect; - } + else { + return expect; } } +} - return function assert(boolExpr, message) { - if (boolExpr === true) return; +return function assert(boolExpr, message) { + if (boolExpr === true) return; - if (typeof boolExpr === "string" && - boolExpr.charAt(0) === "%") { - var nativeCallName = boolExpr; - var $_len = arguments.length;var args = new Array($_len - 2); for(var $_i = 2; $_i < $_len; ++$_i) {args[$_i - 2] = arguments[$_i];} - if (nativeAssert(nativeCallName, args, message) === message) return; - message = (nativeCallName + " !== " + message); - } + if (typeof boolExpr === "string" && + boolExpr.charAt(0) === "%") { + var nativeCallName = boolExpr; + var $_len = arguments.length;var args = new Array($_len - 2); for(var $_i = 2; $_i < $_len; ++$_i) {args[$_i - 2] = arguments[$_i];} + if (nativeAssert(nativeCallName, args, message) === message) return; + message = (nativeCallName + " !== " + message); + } - var ret = new AssertionError(message); - if (Error.captureStackTrace) { - Error.captureStackTrace(ret, assert); - } - if (console && console.error) { - console.error(ret.stack + ""); - } - throw ret; + var ret = new AssertionError(message); + if (Error.captureStackTrace) { + Error.captureStackTrace(ret, assert); + } + if (console && console.error) { + console.error(ret.stack + ""); + } + throw ret; - }; +}; })(); },{}],20:[function(require,module,exports){ @@ -3527,7 +3526,7 @@ Async.prototype._reset = function Async$_reset() { module.exports = new Async(); -},{"./assert.js":19,"./global.js":33,"./queue.js":45,"./schedule.js":48,"./util.js":56}],21:[function(require,module,exports){ +},{"./assert.js":19,"./global.js":33,"./queue.js":44,"./schedule.js":47,"./util.js":55}],21:[function(require,module,exports){ /** * Copyright (c) 2014 Petka Antonov * @@ -3578,36 +3577,34 @@ module.exports = Promise; */ "use strict"; module.exports = function(Promise) { - Promise.prototype.call = function Promise$call(propertyName) { - var $_len = arguments.length;var args = new Array($_len - 1); for(var $_i = 1; $_i < $_len; ++$_i) {args[$_i - 1] = arguments[$_i];} +Promise.prototype.call = function Promise$call(propertyName) { + var $_len = arguments.length;var args = new Array($_len - 1); for(var $_i = 1; $_i < $_len; ++$_i) {args[$_i - 1] = arguments[$_i];} - return this._then(function(obj) { - return obj[propertyName].apply(obj, args); - }, - void 0, - void 0, - void 0, - void 0, - this.call - ); - }; + return this._then(function(obj) { + return obj[propertyName].apply(obj, args); + }, + void 0, + void 0, + void 0, + void 0 + ); +}; - function Promise$getter(obj) { - var prop = typeof this === "string" - ? this - : ("" + this); - return obj[prop]; - } - Promise.prototype.get = function Promise$get(propertyName) { - return this._then( - Promise$getter, - void 0, - void 0, - propertyName, - void 0, - this.get - ); - }; +function Promise$getter(obj) { + var prop = typeof this === "string" + ? this + : ("" + this); + return obj[prop]; +} +Promise.prototype.get = function Promise$get(propertyName) { + return this._then( + Promise$getter, + void 0, + void 0, + propertyName, + void 0 + ); +}; }; },{}],23:[function(require,module,exports){ @@ -3635,61 +3632,57 @@ module.exports = function(Promise) { */ "use strict"; module.exports = function(Promise, INTERNAL) { - var errors = require("./errors.js"); - var async = require("./async.js"); - var ASSERT = require("./assert.js"); - var CancellationError = errors.CancellationError; - var SYNC_TOKEN = {}; - - Promise.prototype._cancel = function Promise$_cancel() { - if (!this.isCancellable()) return this; - var parent; - if ((parent = this._cancellationParent) !== void 0) { - parent.cancel(SYNC_TOKEN); - return; - } - var err = new CancellationError(); - this._attachExtraTrace(err); - this._rejectUnchecked(err); - }; +var errors = require("./errors.js"); +var async = require("./async.js"); +var ASSERT = require("./assert.js"); +var CancellationError = errors.CancellationError; - Promise.prototype.cancel = function Promise$cancel(token) { - if (!this.isCancellable()) return this; - ASSERT(("_cancellationParent" in this), - "\u0022_cancellationParent\u0022 in this"); - if (token === SYNC_TOKEN) { - this._cancel(); - return this; - } - async.invokeLater(this._cancel, this, void 0); - return this; - }; +Promise.prototype._cancel = function Promise$_cancel() { + if (!this.isCancellable()) return this; + var parent; + var promiseToReject = this; + while ((parent = promiseToReject._cancellationParent) !== void 0 && + parent.isCancellable()) { + promiseToReject = parent; + } + ASSERT(promiseToReject.isCancellable(), + "promiseToReject.isCancellable()"); + var err = new CancellationError(); + promiseToReject._attachExtraTrace(err); + promiseToReject._rejectUnchecked(err); +}; - Promise.prototype.cancellable = function Promise$cancellable() { - if (this._cancellable()) return this; - this._setCancellable(); - this._cancellationParent = void 0; - return this; - }; +Promise.prototype.cancel = function Promise$cancel() { + if (!this.isCancellable()) return this; + async.invokeLater(this._cancel, this, void 0); + return this; +}; - Promise.prototype.uncancellable = function Promise$uncancellable() { - var ret = new Promise(INTERNAL); - ret._setTrace(this.uncancellable, this); - ret._follow(this); - ret._unsetCancellable(); - if (this._isBound()) ret._setBoundTo(this._boundTo); - return ret; - }; +Promise.prototype.cancellable = function Promise$cancellable() { + if (this._cancellable()) return this; + this._setCancellable(); + this._cancellationParent = void 0; + return this; +}; - Promise.prototype.fork = - function Promise$fork(didFulfill, didReject, didProgress) { - var ret = this._then(didFulfill, didReject, didProgress, - void 0, void 0, this.fork); +Promise.prototype.uncancellable = function Promise$uncancellable() { + var ret = new Promise(INTERNAL); + ret._setTrace(this); + ret._follow(this); + ret._unsetCancellable(); + if (this._isBound()) ret._setBoundTo(this._boundTo); + return ret; +}; - ret._setCancellable(); - ret._cancellationParent = void 0; - return ret; - }; +Promise.prototype.fork = +function Promise$fork(didFulfill, didReject, didProgress) { + var ret = this._then(didFulfill, didReject, didProgress, + void 0, void 0); + + ret._setCancellable(); + ret._cancellationParent = void 0; + return ret; +}; }; },{"./assert.js":19,"./async.js":20,"./errors.js":27}],24:[function(require,module,exports){ @@ -3722,7 +3715,7 @@ var inherits = require("./util.js").inherits; var defineProperty = require("./es5.js").defineProperty; var rignore = new RegExp( - "\\b(?:[\\w.]*Promise(?:Array|Spawn)?\\$_\\w+|" + + "\\b(?:[a-zA-Z0-9.]+\\$_\\w+|" + "tryCatch(?:1|2|Apply)|new \\w*PromiseArray|" + "\\w*PromiseArray\\.\\w*PromiseArray|" + "setTimeout|CatchFilter\\$_\\w+|makeNodePromisified|processImmediate|" + @@ -3731,7 +3724,6 @@ var rignore = new RegExp( var rtraceline = null; var formatStack = null; -var areNamesMangled = false; function formatNonError(obj) { var str; @@ -3768,15 +3760,7 @@ function snip(str) { } function CapturedTrace(ignoreUntil, isTopLevel) { - ASSERT(((typeof ignoreUntil) === "function"), - "typeof ignoreUntil === \u0022function\u0022"); - if (!areNamesMangled) { - ASSERT(((typeof ignoreUntil.name) === "string"), - "typeof ignoreUntil.name === \u0022string\u0022"); - ASSERT((ignoreUntil.name.length > 0), - "ignoreUntil.name.length > 0"); - } - this.captureStackTrace(ignoreUntil, isTopLevel); + this.captureStackTrace(CapturedTrace, isTopLevel); } inherits(CapturedTrace, Error); @@ -3802,15 +3786,12 @@ function CapturedTrace$PossiblyUnhandledRejection(reason) { console.error(message); } else if (typeof console.log === "function" || - typeof console.error === "object") { + typeof console.log === "object") { console.log(message); } } }; -areNamesMangled = CapturedTrace.prototype.captureStackTrace.name !== - "CapturedTrace$captureStackTrace"; - CapturedTrace.combine = function CapturedTrace$Combine(current, prev) { var curLast = current.length - 1; for (var i = prev.length - 1; i >= 0; --i) { @@ -3829,7 +3810,6 @@ CapturedTrace.combine = function CapturedTrace$Combine(current, prev) { var ret = []; - for (var i = 0, len = lines.length; i < len; ++i) { if ((rignore.test(lines[i]) || @@ -3873,7 +3853,7 @@ var captureStackTrace = (function stackDetection() { } var err = new Error(); - if (!areNamesMangled && typeof err.stack === "string" && + if (typeof err.stack === "string" && typeof "".startsWith === "function" && (err.stack.startsWith("stackDetection@")) && stackDetection.name === "stackDetection") { @@ -3899,22 +3879,12 @@ var captureStackTrace = (function stackDetection() { return formatNonError(error); }; - return function captureStackTrace(o, fn) { - var name = fn.name; + return function captureStackTrace(o) { var stack = new Error().stack; var split = stack.split(rline); - var i, len = split.length; - for (i = 0; i < len; i += 2) { - if (split[i] === name) { - break; - } - } - ASSERT(((i + 2) < split.length), - "i + 2 < split.length"); - split = split.slice(i + 2); - len = split.length - 2; + var len = split.length; var ret = ""; - for (i = 0; i < len; i += 2) { + for (var i = 0; i < len; i += 2) { ret += split[i]; ret += "@"; ret += split[i + 1]; @@ -3943,7 +3913,7 @@ var captureStackTrace = (function stackDetection() { return CapturedTrace; }; -},{"./assert.js":19,"./es5.js":29,"./util.js":56}],25:[function(require,module,exports){ +},{"./assert.js":19,"./es5.js":29,"./util.js":55}],25:[function(require,module,exports){ /** * Copyright (c) 2014 Petka Antonov * @@ -3973,6 +3943,7 @@ var errors = require("./errors.js"); var tryCatch1 = util.tryCatch1; var errorObj = util.errorObj; var keys = require("./es5.js").keys; +var TypeError = errors.TypeError; function CatchFilter(instances, callback, promise) { this._instances = instances; @@ -4038,7 +4009,7 @@ CatchFilter.prototype.doFilter = function CatchFilter$_doFilter(e) { return CatchFilter; }; -},{"./errors.js":27,"./es5.js":29,"./util.js":56}],26:[function(require,module,exports){ +},{"./errors.js":27,"./es5.js":29,"./util.js":55}],26:[function(require,module,exports){ /** * Copyright (c) 2014 Petka Antonov * @@ -4100,12 +4071,10 @@ function Promise$thenReturn(value) { void 0, void 0, void 0, - void 0, - this.thenReturn + void 0 ); } - return this._then(returner, void 0, void 0, - value, void 0, this.thenReturn); + return this._then(returner, void 0, void 0, value, void 0); }; Promise.prototype["throw"] = @@ -4117,16 +4086,14 @@ function Promise$thenThrow(reason) { void 0, void 0, void 0, - void 0, - this.thenThrow + void 0 ); } - return this._then(thrower, void 0, void 0, - reason, void 0, this.thenThrow); + return this._then(thrower, void 0, void 0, reason, void 0); }; }; -},{"./assert.js":19,"./util.js":56}],27:[function(require,module,exports){ +},{"./assert.js":19,"./util.js":55}],27:[function(require,module,exports){ /** * Copyright (c) 2014 Petka Antonov * @@ -4242,7 +4209,7 @@ module.exports = { canAttach: canAttach }; -},{"./es5.js":29,"./global.js":33,"./util.js":56}],28:[function(require,module,exports){ +},{"./es5.js":29,"./global.js":33,"./util.js":55}],28:[function(require,module,exports){ /** * Copyright (c) 2014 Petka Antonov * @@ -4398,45 +4365,43 @@ else { */ "use strict"; module.exports = function(Promise) { - var ASSERT = require("./assert.js"); - var isArray = require("./util.js").isArray; +var ASSERT = require("./assert.js"); +var isArray = require("./util.js").isArray; - function Promise$_filter(booleans) { - var values = this._settledValue; - ASSERT(isArray(values), +function Promise$_filter(booleans) { + var values = this instanceof Promise ? this._settledValue : this; + ASSERT(isArray(values), "isArray(values)"); - ASSERT(isArray(booleans), + ASSERT(isArray(booleans), "isArray(booleans)"); - ASSERT((values.length === booleans.length), + ASSERT((values.length === booleans.length), "values.length === booleans.length"); - var len = values.length; - var ret = new Array(len); - var j = 0; + var len = values.length; + var ret = new Array(len); + var j = 0; - for (var i = 0; i < len; ++i) { - if (booleans[i]) ret[j++] = values[i]; + for (var i = 0; i < len; ++i) { + if (booleans[i]) ret[j++] = values[i]; - } - ret.length = j; - return ret; } + ret.length = j; + return ret; +} - var ref = {ref: null}; - Promise.filter = function Promise$Filter(promises, fn) { - return Promise.map(promises, fn, ref) - ._then(Promise$_filter, void 0, void 0, - ref.ref, void 0, Promise.filter); - }; +var ref = {ref: null}; +Promise.filter = function Promise$Filter(promises, fn) { + return Promise.map(promises, fn, ref) + ._then(Promise$_filter, void 0, void 0, ref.ref, void 0); +}; - Promise.prototype.filter = function Promise$filter(fn) { - return this.map(fn, ref) - ._then(Promise$_filter, void 0, void 0, - ref.ref, void 0, this.filter); - }; +Promise.prototype.filter = function Promise$filter(fn) { + return this.map(fn, ref) + ._then(Promise$_filter, void 0, void 0, ref.ref, void 0); +}; }; -},{"./assert.js":19,"./util.js":56}],31:[function(require,module,exports){ +},{"./assert.js":19,"./util.js":55}],31:[function(require,module,exports){ /** * Copyright (c) 2014 Petka Antonov * @@ -4461,116 +4426,107 @@ module.exports = function(Promise) { */ "use strict"; module.exports = function(Promise, NEXT_FILTER) { - var util = require("./util.js"); - var wrapsPrimitiveReceiver = util.wrapsPrimitiveReceiver; - var isPrimitive = util.isPrimitive; - var thrower = util.thrower; +var util = require("./util.js"); +var wrapsPrimitiveReceiver = util.wrapsPrimitiveReceiver; +var isPrimitive = util.isPrimitive; +var thrower = util.thrower; - function returnThis() { - return this; - } - function throwThis() { - throw this; - } - function makeReturner(r) { - return function Promise$_returner() { - return r; - }; - } - function makeThrower(r) { - return function Promise$_thrower() { - throw r; - }; +function returnThis() { + return this; +} +function throwThis() { + throw this; +} +function return$(r) { + return function Promise$_returner() { + return r; + }; +} +function throw$(r) { + return function Promise$_thrower() { + throw r; + }; +} +function promisedFinally(ret, reasonOrValue, isFulfilled) { + var then; + if (wrapsPrimitiveReceiver && isPrimitive(reasonOrValue)) { + then = isFulfilled ? return$(reasonOrValue) : throw$(reasonOrValue); } - function promisedFinally(ret, reasonOrValue, isFulfilled) { - var useConstantFunction = - wrapsPrimitiveReceiver && isPrimitive(reasonOrValue); - - if (isFulfilled) { - return ret._then( - useConstantFunction - ? returnThis - : makeReturner(reasonOrValue), - thrower, void 0, reasonOrValue, void 0, promisedFinally); - } - else { - return ret._then( - useConstantFunction - ? throwThis - : makeThrower(reasonOrValue), - thrower, void 0, reasonOrValue, void 0, promisedFinally); - } + else { + then = isFulfilled ? returnThis : throwThis; } + return ret._then(then, thrower, void 0, reasonOrValue, void 0); +} - function finallyHandler(reasonOrValue) { - var promise = this.promise; - var handler = this.handler; +function finallyHandler(reasonOrValue) { + var promise = this.promise; + var handler = this.handler; - var ret = promise._isBound() - ? handler.call(promise._boundTo) - : handler(); + var ret = promise._isBound() + ? handler.call(promise._boundTo) + : handler(); - if (ret !== void 0) { - var maybePromise = Promise._cast(ret, finallyHandler, void 0); - if (maybePromise instanceof Promise) { - return promisedFinally(maybePromise, reasonOrValue, - promise.isFulfilled()); - } + if (ret !== void 0) { + var maybePromise = Promise._cast(ret, void 0); + if (maybePromise instanceof Promise) { + return promisedFinally(maybePromise, reasonOrValue, + promise.isFulfilled()); } + } - if (promise.isRejected()) { - NEXT_FILTER.e = reasonOrValue; - return NEXT_FILTER; - } - else { - return reasonOrValue; - } + if (promise.isRejected()) { + NEXT_FILTER.e = reasonOrValue; + return NEXT_FILTER; } + else { + return reasonOrValue; + } +} - function tapHandler(value) { - var promise = this.promise; - var handler = this.handler; +function tapHandler(value) { + var promise = this.promise; + var handler = this.handler; - var ret = promise._isBound() - ? handler.call(promise._boundTo, value) - : handler(value); + var ret = promise._isBound() + ? handler.call(promise._boundTo, value) + : handler(value); - if (ret !== void 0) { - var maybePromise = Promise._cast(ret, tapHandler, void 0); - if (maybePromise instanceof Promise) { - return promisedFinally(maybePromise, value, true); - } + if (ret !== void 0) { + var maybePromise = Promise._cast(ret, void 0); + if (maybePromise instanceof Promise) { + return promisedFinally(maybePromise, value, true); } - return value; } + return value; +} - Promise.prototype._passThroughHandler = - function Promise$_passThroughHandler(handler, isFinally, caller) { - if (typeof handler !== "function") return this.then(); - - var promiseAndHandler = { - promise: this, - handler: handler - }; +Promise.prototype._passThroughHandler = +function Promise$_passThroughHandler(handler, isFinally) { + if (typeof handler !== "function") return this.then(); - return this._then( - isFinally ? finallyHandler : tapHandler, - isFinally ? finallyHandler : void 0, void 0, - promiseAndHandler, void 0, caller); + var promiseAndHandler = { + promise: this, + handler: handler }; - Promise.prototype.lastly = - Promise.prototype["finally"] = function Promise$finally(handler) { - return this._passThroughHandler(handler, true, this.lastly); - }; + return this._then( + isFinally ? finallyHandler : tapHandler, + isFinally ? finallyHandler : void 0, void 0, + promiseAndHandler, void 0); +}; - Promise.prototype.tap = function Promise$tap(handler) { - return this._passThroughHandler(handler, false, this.tap); - }; +Promise.prototype.lastly = +Promise.prototype["finally"] = function Promise$finally(handler) { + return this._passThroughHandler(handler, true); }; -},{"./util.js":56}],32:[function(require,module,exports){ +Promise.prototype.tap = function Promise$tap(handler) { + return this._passThroughHandler(handler, false); +}; +}; + +},{"./util.js":55}],32:[function(require,module,exports){ /** * Copyright (c) 2014 Petka Antonov * @@ -4595,40 +4551,40 @@ module.exports = function(Promise, NEXT_FILTER) { */ "use strict"; module.exports = function(Promise, apiRejection, INTERNAL) { - var PromiseSpawn = require("./promise_spawn.js")(Promise, INTERNAL); - var errors = require("./errors.js"); - var TypeError = errors.TypeError; - var deprecated = require("./util.js").deprecated; - - Promise.coroutine = function Promise$Coroutine(generatorFunction) { - if (typeof generatorFunction !== "function") { - throw new TypeError("generatorFunction must be a function"); - } - var PromiseSpawn$ = PromiseSpawn; - return function anonymous() { - var generator = generatorFunction.apply(this, arguments); - var spawn = new PromiseSpawn$(void 0, void 0, anonymous); - spawn._generator = generator; - spawn._next(void 0); - return spawn.promise(); - }; +var PromiseSpawn = require("./promise_spawn.js")(Promise, INTERNAL); +var errors = require("./errors.js"); +var TypeError = errors.TypeError; +var deprecated = require("./util.js").deprecated; + +Promise.coroutine = function Promise$Coroutine(generatorFunction) { + if (typeof generatorFunction !== "function") { + throw new TypeError("generatorFunction must be a function"); + } + var PromiseSpawn$ = PromiseSpawn; + return function () { + var generator = generatorFunction.apply(this, arguments); + var spawn = new PromiseSpawn$(void 0, void 0); + spawn._generator = generator; + spawn._next(void 0); + return spawn.promise(); }; +}; - Promise.coroutine.addYieldHandler = PromiseSpawn.addYieldHandler; +Promise.coroutine.addYieldHandler = PromiseSpawn.addYieldHandler; - Promise.spawn = function Promise$Spawn(generatorFunction) { - deprecated("Promise.spawn is deprecated. Use Promise.coroutine instead."); - if (typeof generatorFunction !== "function") { - return apiRejection("generatorFunction must be a function"); - } - var spawn = new PromiseSpawn(generatorFunction, this, Promise.spawn); - var ret = spawn.promise(); - spawn._run(Promise.spawn); - return ret; - }; +Promise.spawn = function Promise$Spawn(generatorFunction) { + deprecated("Promise.spawn is deprecated. Use Promise.coroutine instead."); + if (typeof generatorFunction !== "function") { + return apiRejection("generatorFunction must be a function"); + } + var spawn = new PromiseSpawn(generatorFunction, this); + var ret = spawn.promise(); + spawn._run(Promise.spawn); + return ret; +}; }; -},{"./errors.js":27,"./promise_spawn.js":41,"./util.js":56}],33:[function(require,module,exports){ +},{"./errors.js":27,"./promise_spawn.js":40,"./util.js":55}],33:[function(require,module,exports){ var process=require("__browserify_process"),global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {};/** * Copyright (c) 2014 Petka Antonov * @@ -4653,23 +4609,23 @@ var process=require("__browserify_process"),global=typeof self !== "undefined" ? */ "use strict"; module.exports = (function(){ - if (typeof this !== "undefined") { - return this; - } - if (typeof process !== "undefined" && - typeof global !== "undefined" && - typeof process.execPath === "string") { - return global; - } - if (typeof window !== "undefined" && - typeof document !== "undefined" && - typeof navigator !== "undefined" && navigator !== null && - typeof navigator.appName === "string") { - if(window.wrappedJSObject !== undefined){ - return window.wrappedJSObject; - } - return window; - } +if (typeof this !== "undefined") { + return this; +} +if (typeof process !== "undefined" && + typeof global !== "undefined" && + typeof process.execPath === "string") { + return global; +} +if (typeof window !== "undefined" && + typeof document !== "undefined" && + typeof navigator !== "undefined" && navigator !== null && + typeof navigator.appName === "string") { + if(window.wrappedJSObject !== undefined){ + return window.wrappedJSObject; + } + return window; +} })(); },{"__browserify_process":16}],34:[function(require,module,exports){ @@ -4696,116 +4652,164 @@ module.exports = (function(){ * */ "use strict"; -module.exports = function( - Promise, Promise$_CreatePromiseArray, PromiseArray, apiRejection) { +module.exports = function(Promise, PromiseArray, INTERNAL, apiRejection) { - var ASSERT = require("./assert.js"); +var ASSERT = require("./assert.js"); +var all = Promise.all; +var util = require("./util.js"); +var canAttach = require("./errors.js").canAttach; +var isArray = util.isArray; +var _cast = Promise._cast; - function Promise$_mapper(values) { - var fn = this; - var receiver = void 0; +function unpack(values) { + ASSERT((this.length === 3), + "this.length === 3"); + return Promise$_Map(values, this[0], this[1], this[2]); +} + +function Promise$_Map(promises, fn, useBound, ref) { + if (typeof fn !== "function") { + return apiRejection("fn must be a function"); + } - if (typeof fn !== "function") { - receiver = fn.receiver; - fn = fn.fn; + var receiver = void 0; + if (useBound === true) { + if (promises._isBound()) { + receiver = promises._boundTo; } - ASSERT(((typeof fn) === "function"), - "typeof fn === \u0022function\u0022"); - var shouldDefer = false; - - var ret = new Array(values.length); - - if (receiver === void 0) { - for (var i = 0, len = values.length; i < len; ++i) { - var value = fn(values[i], i, len); - if (!shouldDefer) { - var maybePromise = Promise._cast(value, - Promise$_mapper, void 0); - if (maybePromise instanceof Promise) { - if (maybePromise.isFulfilled()) { - ret[i] = maybePromise._settledValue; - continue; - } - else { - shouldDefer = true; - } - value = maybePromise; - } + } + else if (useBound !== false) { + receiver = useBound; + } + + var shouldUnwrapItems = ref !== void 0; + if (shouldUnwrapItems) ref.ref = promises; + + if (promises instanceof Promise) { + var pack = [fn, receiver, ref]; + return promises._then(unpack, void 0, void 0, pack, void 0); + } + else if (!isArray(promises)) { + return apiRejection("expecting an array, a promise or a thenable"); + } + + var promise = new Promise(INTERNAL); + if (receiver !== void 0) promise._setBoundTo(receiver); + promise._setTrace(void 0); + + var mapping = new Mapping(promise, + fn, + promises, + receiver, + shouldUnwrapItems); + mapping.init(); + return promise; +} + +var pending = {}; +function Mapping(promise, callback, items, receiver, shouldUnwrapItems) { + this.shouldUnwrapItems = shouldUnwrapItems; + this.index = 0; + this.items = items; + this.callback = callback; + this.receiver = receiver; + this.promise = promise; + this.result = new Array(items.length); +} +util.inherits(Mapping, PromiseArray); + +Mapping.prototype.init = function Mapping$init() { + var items = this.items; + var len = items.length; + var result = this.result; + var isRejected = false; + for (var i = 0; i < len; ++i) { + var maybePromise = _cast(items[i], void 0); + if (maybePromise instanceof Promise) { + if (maybePromise.isPending()) { + result[i] = pending; + maybePromise._proxyPromiseArray(this, i); + } + else if (maybePromise.isFulfilled()) { + result[i] = maybePromise.value(); + } + else { + maybePromise._unsetRejectionIsUnhandled(); + if (!isRejected) { + this.reject(maybePromise.reason()); + isRejected = true; } - ret[i] = value; } } else { - for (var i = 0, len = values.length; i < len; ++i) { - var value = fn.call(receiver, values[i], i, len); - if (!shouldDefer) { - var maybePromise = Promise._cast(value, - Promise$_mapper, void 0); - if (maybePromise instanceof Promise) { - if (maybePromise.isFulfilled()) { - ret[i] = maybePromise._settledValue; - continue; - } - else { - shouldDefer = true; - } - value = maybePromise; - } - } - ret[i] = value; - } + result[i] = maybePromise; } - return shouldDefer - ? Promise$_CreatePromiseArray(ret, PromiseArray, - Promise$_mapper, void 0).promise() - : ret; } + if (!isRejected) this.iterate(); +}; - function Promise$_Map(promises, fn, useBound, caller, ref) { - if (typeof fn !== "function") { - return apiRejection("fn must be a function"); - } +Mapping.prototype.isResolved = function Mapping$isResolved() { + return this.promise === null; +}; - if (useBound === true && promises._isBound()) { - fn = { - fn: fn, - receiver: promises._boundTo - }; - } +Mapping.prototype._promiseProgressed = +function Mapping$_promiseProgressed(value) { + if (this.isResolved()) return; + this.promise._progress(value); +}; - var ret = Promise$_CreatePromiseArray( - promises, - PromiseArray, - caller, - useBound === true && promises._isBound() - ? promises._boundTo - : void 0 - ).promise(); +Mapping.prototype._promiseFulfilled = +function Mapping$_promiseFulfilled(value, index) { + if (this.isResolved()) return; + this.result[index] = value; + if (this.shouldUnwrapItems) this.items[index] = value; + if (this.index === index) this.iterate(); +}; - if (ref !== void 0) { - ref.ref = ret; - } +Mapping.prototype._promiseRejected = +function Mapping$_promiseRejected(reason) { + this.reject(reason); +}; - return ret._then( - Promise$_mapper, - void 0, - void 0, - fn, - void 0, - caller - ); +Mapping.prototype.reject = function Mapping$reject(reason) { + if (this.isResolved()) return; + var trace = canAttach(reason) ? reason : new Error(reason + ""); + this.promise._attachExtraTrace(trace); + this.promise._reject(reason, trace); +}; + +Mapping.prototype.iterate = function Mapping$iterate() { + var i = this.index; + var items = this.items; + var result = this.result; + var len = items.length; + var result = this.result; + var receiver = this.receiver; + var callback = this.callback; + + for (; i < len; ++i) { + var value = result[i]; + if (value === pending) { + this.index = i; + return; + } + try { result[i] = callback.call(receiver, value, i, len); } + catch (e) { return this.reject(e); } } + this.promise._follow(all(result)); + this.items = this.result = this.callback = this.promise = null; +}; - Promise.prototype.map = function Promise$map(fn, ref) { - return Promise$_Map(this, fn, true, this.map, ref); - }; +Promise.prototype.map = function Promise$map(fn, ref) { + return Promise$_Map(this, fn, true, ref); +}; - Promise.map = function Promise$Map(promises, fn, ref) { - return Promise$_Map(promises, fn, false, Promise.map, ref); - }; +Promise.map = function Promise$Map(promises, fn, ref) { + return Promise$_Map(promises, fn, false, ref); +}; }; -},{"./assert.js":19}],35:[function(require,module,exports){ +},{"./assert.js":19,"./errors.js":27,"./util.js":55}],35:[function(require,module,exports){ /** * Copyright (c) 2014 Petka Antonov * @@ -4830,53 +4834,52 @@ module.exports = function( */ "use strict"; module.exports = function(Promise) { - var util = require("./util.js"); - var async = require("./async.js"); - var ASSERT = require("./assert.js"); - var tryCatch2 = util.tryCatch2; - var tryCatch1 = util.tryCatch1; - var errorObj = util.errorObj; - - function thrower(r) { - throw r; - } +var util = require("./util.js"); +var async = require("./async.js"); +var ASSERT = require("./assert.js"); +var tryCatch2 = util.tryCatch2; +var tryCatch1 = util.tryCatch1; +var errorObj = util.errorObj; + +function thrower(r) { + throw r; +} - function Promise$_successAdapter(val, receiver) { - var nodeback = this; - ASSERT(((typeof nodeback) == "function"), +function Promise$_successAdapter(val, receiver) { + var nodeback = this; + ASSERT(((typeof nodeback) == "function"), "typeof nodeback == \u0022function\u0022"); - var ret = tryCatch2(nodeback, receiver, null, val); - if (ret === errorObj) { - async.invokeLater(thrower, void 0, ret.e); - } + var ret = tryCatch2(nodeback, receiver, null, val); + if (ret === errorObj) { + async.invokeLater(thrower, void 0, ret.e); } - function Promise$_errorAdapter(reason, receiver) { - var nodeback = this; - ASSERT(((typeof nodeback) == "function"), +} +function Promise$_errorAdapter(reason, receiver) { + var nodeback = this; + ASSERT(((typeof nodeback) == "function"), "typeof nodeback == \u0022function\u0022"); - var ret = tryCatch1(nodeback, receiver, reason); - if (ret === errorObj) { - async.invokeLater(thrower, void 0, ret.e); - } + var ret = tryCatch1(nodeback, receiver, reason); + if (ret === errorObj) { + async.invokeLater(thrower, void 0, ret.e); } +} - Promise.prototype.nodeify = function Promise$nodeify(nodeback) { - if (typeof nodeback == "function") { - this._then( - Promise$_successAdapter, - Promise$_errorAdapter, - void 0, - nodeback, - this._isBound() ? this._boundTo : null, - this.nodeify - ); - return; - } - return this; - }; +Promise.prototype.nodeify = function Promise$nodeify(nodeback) { + if (typeof nodeback == "function") { + this._then( + Promise$_successAdapter, + Promise$_errorAdapter, + void 0, + nodeback, + this._isBound() ? this._boundTo : null + ); + return; + } + return this; +}; }; -},{"./assert.js":19,"./async.js":20,"./util.js":56}],36:[function(require,module,exports){ +},{"./assert.js":19,"./async.js":20,"./util.js":55}],36:[function(require,module,exports){ /** * Copyright (c) 2014 Petka Antonov * @@ -4901,109 +4904,107 @@ module.exports = function(Promise) { */ "use strict"; 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; - - Promise.prototype.progressed = function Promise$progressed(handler) { - return this._then(void 0, void 0, handler, - void 0, void 0, this.progressed); - }; +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; - Promise.prototype._progress = function Promise$_progress(progressValue) { - if (this._isFollowingOrFulfilledOrRejected()) return; - this._progressUnchecked(progressValue); +Promise.prototype.progressed = function Promise$progressed(handler) { + return this._then(void 0, void 0, handler, void 0, void 0); +}; - }; +Promise.prototype._progress = function Promise$_progress(progressValue) { + if (this._isFollowingOrFulfilledOrRejected()) return; + this._progressUnchecked(progressValue); + +}; - Promise.prototype._progressHandlerAt = - function Promise$_progressHandlerAt(index) { - ASSERT(((typeof index) === "number"), +Promise.prototype._progressHandlerAt = +function Promise$_progressHandlerAt(index) { + ASSERT(((typeof index) === "number"), "typeof index === \u0022number\u0022"); - ASSERT((index >= 0), + ASSERT((index >= 0), "index >= 0"); - ASSERT(((index % 5) === 0), + ASSERT(((index % 5) === 0), "index % CALLBACK_SIZE === 0"); - if (index === 0) return this._progressHandler0; - return this[index + 2 - 5]; - }; + if (index === 0) return this._progressHandler0; + return this[index + 2 - 5]; +}; - Promise.prototype._doProgressWith = - function Promise$_doProgressWith(progression) { - var progressValue = progression.value; - var handler = progression.handler; - var promise = progression.promise; - var receiver = progression.receiver; +Promise.prototype._doProgressWith = +function Promise$_doProgressWith(progression) { + var progressValue = progression.value; + var handler = progression.handler; + var promise = progression.promise; + var receiver = progression.receiver; - ASSERT(((typeof handler) === "function"), + ASSERT(((typeof handler) === "function"), "typeof handler === \u0022function\u0022"); - ASSERT(Promise.is(promise), - "Promise.is(promise)"); - - this._pushContext(); - var ret = tryCatch1(handler, receiver, progressValue); - this._popContext(); - - if (ret === errorObj) { - if (ret.e != null && - ret.e.name !== "StopProgressPropagation") { - var trace = errors.canAttach(ret.e) - ? ret.e : new Error(ret.e + ""); - promise._attachExtraTrace(trace); - promise._progress(ret.e); - } - } - else if (Promise.is(ret)) { - ret._then(promise._progress, null, null, promise, void 0, - this._progress); - } - else { - promise._progress(ret); - } - }; + ASSERT((promise instanceof Promise), + "promise instanceof Promise"); + this._pushContext(); + var ret = tryCatch1(handler, receiver, progressValue); + this._popContext(); - Promise.prototype._progressUnchecked = - function Promise$_progressUnchecked(progressValue) { - if (!this.isPending()) return; - var len = this._length(); + if (ret === errorObj) { + if (ret.e != null && + ret.e.name !== "StopProgressPropagation") { + var trace = errors.canAttach(ret.e) + ? ret.e : new Error(ret.e + ""); + promise._attachExtraTrace(trace); + promise._progress(ret.e); + } + } + else if (ret instanceof Promise) { + ret._then(promise._progress, null, null, promise, void 0); + } + else { + promise._progress(ret); + } +}; - for (var i = 0; i < len; i += 5) { - var handler = this._progressHandlerAt(i); - var promise = this._promiseAt(i); - if (!Promise.is(promise)) { - var receiver = this._receiverAt(i); - if (typeof handler === "function") { - handler.call(receiver, progressValue, promise); - } - else if (Promise.is(receiver) && receiver._isProxied()) { - receiver._progressUnchecked(progressValue); - } - else if (isPromiseArrayProxy(receiver, promise)) { - receiver._promiseProgressed(progressValue, promise); - } - continue; - } +Promise.prototype._progressUnchecked = +function Promise$_progressUnchecked(progressValue) { + if (!this.isPending()) return; + var len = this._length(); + var progress = this._progress; + for (var i = 0; i < len; i += 5) { + var handler = this._progressHandlerAt(i); + var promise = this._promiseAt(i); + if (!(promise instanceof Promise)) { + var receiver = this._receiverAt(i); if (typeof handler === "function") { - async.invoke(this._doProgressWith, this, { - handler: handler, - promise: promise, - receiver: this._receiverAt(i), - value: progressValue - }); + handler.call(receiver, progressValue, promise); } - else { - async.invoke(promise._progress, promise, progressValue); + else if (receiver instanceof Promise && receiver._isProxied()) { + receiver._progressUnchecked(progressValue); + } + else if (isPromiseArrayProxy(receiver, promise)) { + receiver._promiseProgressed(progressValue, promise); } + continue; } - }; + + if (typeof handler === "function") { + async.invoke(this._doProgressWith, this, { + handler: handler, + promise: promise, + receiver: this._receiverAt(i), + value: progressValue + }); + } + else { + async.invoke(progress, promise, progressValue); + } + } +}; }; -},{"./assert.js":19,"./async.js":20,"./errors.js":27,"./util.js":56}],37:[function(require,module,exports){ +},{"./assert.js":19,"./async.js":20,"./errors.js":27,"./util.js":55}],37:[function(require,module,exports){ var process=require("__browserify_process");/** * Copyright (c) 2014 Petka Antonov * @@ -5100,7 +5101,7 @@ function Promise(resolver) { Promise.prototype.bind = function Promise$bind(thisArg) { var ret = new Promise(INTERNAL); - if (debugging) ret._setTrace(this.bind, this); + ret._setTrace(this); ret._follow(this); ret._setBoundTo(thisArg); if (this._cancellable()) { @@ -5139,52 +5140,33 @@ function Promise$catch(fn) { catchInstances.length = j; fn = arguments[i]; - this._resetTrace(this.caught); + this._resetTrace(); var catchFilter = new CatchFilter(catchInstances, fn, this); return this._then(void 0, catchFilter.doFilter, void 0, - catchFilter, void 0, this.caught); + catchFilter, void 0); } - return this._then(void 0, fn, void 0, void 0, void 0, this.caught); + return this._then(void 0, fn, void 0, void 0, void 0); }; Promise.prototype.then = function Promise$then(didFulfill, didReject, didProgress) { return this._then(didFulfill, didReject, didProgress, - void 0, void 0, this.then); + void 0, void 0); }; Promise.prototype.done = function Promise$done(didFulfill, didReject, didProgress) { var promise = this._then(didFulfill, didReject, didProgress, - void 0, void 0, this.done); + void 0, void 0); promise._setIsFinal(); }; Promise.prototype.spread = function Promise$spread(didFulfill, didReject) { return this._then(didFulfill, didReject, void 0, - APPLY, void 0, this.spread); -}; - -Promise.prototype.isFulfilled = function Promise$isFulfilled() { - return (this._bitField & 268435456) > 0; -}; - - -Promise.prototype.isRejected = function Promise$isRejected() { - return (this._bitField & 134217728) > 0; + APPLY, void 0); }; -Promise.prototype.isPending = function Promise$isPending() { - return !this.isResolved(); -}; - - -Promise.prototype.isResolved = function Promise$isResolved() { - return (this._bitField & 402653184) > 0; -}; - - Promise.prototype.isCancellable = function Promise$isCancellable() { return !this.isResolved() && this._cancellable(); @@ -5209,38 +5191,34 @@ Promise.prototype.toJSON = function Promise$toJSON() { }; Promise.prototype.all = function Promise$all() { - return Promise$_all(this, true, this.all); + return Promise$_all(this, true); }; Promise.is = isPromise; -function Promise$_all(promises, useBound, caller) { +function Promise$_all(promises, useBound) { return Promise$_CreatePromiseArray( promises, PromiseArray, - caller, useBound === true && promises._isBound() ? promises._boundTo : void 0 ).promise(); } Promise.all = function Promise$All(promises) { - return Promise$_all(promises, false, Promise.all); + return Promise$_all(promises, false); }; Promise.join = function Promise$Join() { var $_len = arguments.length;var args = new Array($_len); for(var $_i = 0; $_i < $_len; ++$_i) {args[$_i] = arguments[$_i];} - return Promise$_CreatePromiseArray( - args, PromiseArray, Promise.join, void 0).promise(); + return Promise$_CreatePromiseArray(args, PromiseArray, void 0).promise(); }; Promise.resolve = Promise.fulfilled = -function Promise$Resolve(value, caller) { +function Promise$Resolve(value) { var ret = new Promise(INTERNAL); - if (debugging) ret._setTrace(typeof caller === "function" - ? caller - : Promise.resolve, void 0); + ret._setTrace(void 0); if (ret._tryFollow(value)) { return ret; } @@ -5252,7 +5230,7 @@ function Promise$Resolve(value, caller) { Promise.reject = Promise.rejected = function Promise$Reject(reason) { var ret = new Promise(INTERNAL); - if (debugging) ret._setTrace(Promise.reject, void 0); + ret._setTrace(void 0); markAsOriginatingFromRejection(reason); ret._cleanValues(); ret._setRejected(); @@ -5270,7 +5248,7 @@ Promise.prototype.error = function Promise$_error(fn) { }; Promise.prototype._resolveFromSyncValue = -function Promise$_resolveFromSyncValue(value, caller) { +function Promise$_resolveFromSyncValue(value) { if (value === errorObj) { this._cleanValues(); this._setRejected(); @@ -5278,7 +5256,7 @@ function Promise$_resolveFromSyncValue(value, caller) { this._ensurePossibleRejectionHandled(); } else { - var maybePromise = Promise._cast(value, caller, void 0); + var maybePromise = Promise._cast(value, void 0); if (maybePromise instanceof Promise) { this._follow(maybePromise); } @@ -5305,14 +5283,13 @@ Promise.method = function Promise$_Method(fn) { value = tryCatchApply(fn, args, this); break; } var ret = new Promise(INTERNAL); - if (debugging) ret._setTrace(Promise$_method, void 0); - ret._resolveFromSyncValue(value, Promise$_method); + ret._setTrace(void 0); + ret._resolveFromSyncValue(value); return ret; }; }; Promise.attempt = Promise["try"] = function Promise$_Try(fn, args, ctx) { - if (typeof fn !== "function") { return apiRejection("fn must be a function"); } @@ -5321,45 +5298,43 @@ Promise.attempt = Promise["try"] = function Promise$_Try(fn, args, ctx) { : tryCatch1(fn, ctx, args); var ret = new Promise(INTERNAL); - if (debugging) ret._setTrace(Promise.attempt, void 0); - ret._resolveFromSyncValue(value, Promise.attempt); + ret._setTrace(void 0); + ret._resolveFromSyncValue(value); return ret; }; -Promise.defer = Promise.pending = function Promise$Defer(caller) { +Promise.defer = Promise.pending = function Promise$Defer() { var promise = new Promise(INTERNAL); - if (debugging) promise._setTrace(typeof caller === "function" - ? caller : Promise.defer, void 0); + promise._setTrace(void 0); return new PromiseResolver(promise); }; Promise.bind = function Promise$Bind(thisArg) { var ret = new Promise(INTERNAL); - if (debugging) ret._setTrace(Promise.bind, void 0); + ret._setTrace(void 0); ret._setFulfilled(); ret._setBoundTo(thisArg); return ret; }; -Promise.cast = function Promise$_Cast(obj, caller) { - if (typeof caller !== "function") { - caller = Promise.cast; - } - var ret = Promise._cast(obj, caller, void 0); +Promise.cast = function Promise$_Cast(obj) { + var ret = Promise._cast(obj, void 0); if (!(ret instanceof Promise)) { - return Promise.resolve(ret, caller); + return Promise.resolve(ret); } return ret; }; Promise.onPossiblyUnhandledRejection = function Promise$OnPossiblyUnhandledRejection(fn) { - if (typeof fn === "function") { - CapturedTrace.possiblyUnhandledRejection = fn; - } - else { - CapturedTrace.possiblyUnhandledRejection = void 0; - } + CapturedTrace.possiblyUnhandledRejection = typeof fn === "function" + ? fn : void 0; +}; + +var unhandledRejectionHandled; +Promise.onUnhandledRejectionHandled = +function Promise$onUnhandledRejectionHandled(fn) { + unhandledRejectionHandled = typeof fn === "function" ? fn : void 0; }; var debugging = true || !!( @@ -5388,7 +5363,7 @@ Promise.prototype._setProxyHandlers = function Promise$_setProxyHandlers(receiver, promiseSlotValue) { var index = this._length(); - if (index >= 1048575 - 5) { + if (index >= 524287 - 5) { index = 0; this._setLength(0); } @@ -5439,20 +5414,17 @@ function Promise$_then( didReject, didProgress, receiver, - internalData, - caller + internalData ) { - ASSERT((arguments.length === 6), - "arguments.length === 6"); + ASSERT((arguments.length === 5), + "arguments.length === 5"); var haveInternalData = internalData !== void 0; var ret = haveInternalData ? internalData : new Promise(INTERNAL); if (debugging && !haveInternalData) { var haveSameContext = this._peekContext() === this._traceParent; ret._traceParent = haveSameContext ? this._traceParent : this; - ret._setTrace(typeof caller === "function" - ? caller - : this._then, this); + ret._setTrace(this); } if (!haveInternalData && this._isBound()) { @@ -5479,7 +5451,7 @@ Promise.prototype._length = function Promise$_length() { "isPromise(this)"); ASSERT((arguments.length === 0), "arguments.length === 0"); - return this._bitField & 1048575; + return this._bitField & 524287; }; Promise.prototype._isFollowingOrFulfilledOrRejected = @@ -5492,8 +5464,8 @@ Promise.prototype._isFollowing = function Promise$_isFollowing() { }; Promise.prototype._setLength = function Promise$_setLength(len) { - this._bitField = (this._bitField & -1048576) | - (len & 1048575); + this._bitField = (this._bitField & -524288) | + (len & 524287); }; Promise.prototype._setFulfilled = function Promise$_setFulfilled() { @@ -5538,6 +5510,10 @@ function Promise$_setRejectionIsUnhandled() { Promise.prototype._unsetRejectionIsUnhandled = function Promise$_unsetRejectionIsUnhandled() { this._bitField = this._bitField & (~2097152); + if (this._isUnhandledRejectionNotified()) { + this._unsetUnhandledRejectionIsNotified(); + this._notifyUnhandledRejectionIsHandled(); + } }; Promise.prototype._isRejectionUnhandled = @@ -5545,6 +5521,21 @@ function Promise$_isRejectionUnhandled() { return (this._bitField & 2097152) > 0; }; +Promise.prototype._setUnhandledRejectionIsNotified = +function Promise$_setUnhandledRejectionIsNotified() { + this._bitField = this._bitField | 524288; +}; + +Promise.prototype._unsetUnhandledRejectionIsNotified = +function Promise$_unsetUnhandledRejectionIsNotified() { + this._bitField = this._bitField & (~524288); +}; + +Promise.prototype._isUnhandledRejectionNotified = +function Promise$_isUnhandledRejectionNotified() { + return (this._bitField & 524288) > 0; +}; + Promise.prototype._setCarriedStackTrace = function Promise$_setCarriedStackTrace(capturedTrace) { ASSERT(this.isRejected(), @@ -5663,11 +5654,9 @@ function Promise$_resolveFromResolver(resolver) { ASSERT(((typeof resolver) === "function"), "typeof resolver === \u0022function\u0022"); var promise = this; - var localDebugging = debugging; - if (localDebugging) { - this._setTrace(this._resolveFromResolver, void 0); - this._pushContext(); - } + this._setTrace(void 0); + this._pushContext(); + function Promise$_resolver(val) { if (promise._tryFollow(val)) { return; @@ -5681,7 +5670,7 @@ function Promise$_resolveFromResolver(resolver) { promise._reject(val, trace === val ? void 0 : trace); } var r = tryCatch2(resolver, void 0, Promise$_resolver, Promise$_rejecter); - if (localDebugging) this._popContext(); + this._popContext(); if (r !== void 0 && r === errorObj) { var e = r.e; @@ -5699,7 +5688,7 @@ Promise.prototype._addCallbacks = function Promise$_addCallbacks( ) { var index = this._length(); - if (index >= 1048575 - 5) { + if (index >= 524287 - 5) { index = 0; this._setLength(0); } @@ -5754,11 +5743,11 @@ function Promise$_spreadSlowCase(targetFn, promise, values, boundTo) { var promiseForAll = Promise$_CreatePromiseArray - (values, PromiseArray, this._spreadSlowCase, boundTo) + (values, PromiseArray, boundTo) .promise() ._then(function() { return targetFn.apply(boundTo, arguments); - }, void 0, void 0, APPLY, void 0, this._spreadSlowCase); + }, void 0, void 0, APPLY, void 0); promise._follow(promiseForAll); }; @@ -5767,9 +5756,8 @@ Promise.prototype._callSpread = function Promise$_callSpread(handler, promise, value, localDebugging) { var boundTo = this._isBound() ? this._boundTo : void 0; if (isArray(value)) { - var caller = this._settlePromiseFromHandler; for (var i = 0, len = value.length; i < len; ++i) { - if (isPromise(Promise._cast(value[i], caller, void 0))) { + if (isPromise(Promise._cast(value[i], void 0))) { this._spreadSlowCase(handler, promise, value, boundTo); return; } @@ -5818,10 +5806,7 @@ function Promise$_settlePromiseFromHandler( promise._rejectUnchecked(err, trace); } else { - var castValue = Promise._cast(x, - localDebugging ? this._settlePromiseFromHandler : void 0, - promise); - + var castValue = Promise._cast(x, promise); if (isPromise(castValue)) { if (castValue.isRejected() && !castValue._isCarryingStackTrace() && @@ -5885,7 +5870,7 @@ function Promise$_tryFollow(value) { value === this) { return false; } - var maybePromise = Promise._cast(value, this._tryFollow, void 0); + var maybePromise = Promise._cast(value, void 0); if (!isPromise(maybePromise)) { return false; } @@ -5893,22 +5878,17 @@ function Promise$_tryFollow(value) { return true; }; -Promise.prototype._resetTrace = function Promise$_resetTrace(caller) { +Promise.prototype._resetTrace = function Promise$_resetTrace() { if (debugging) { - var context = this._peekContext(); - var isTopLevel = context === void 0; - this._trace = new CapturedTrace( - typeof caller === "function" - ? caller - : this._resetTrace, - isTopLevel - ); + this._trace = new CapturedTrace(this._peekContext() === void 0); } }; -Promise.prototype._setTrace = function Promise$_setTrace(caller, parent) { +Promise.prototype._setTrace = function Promise$_setTrace(parent) { ASSERT((this._trace == null), "this._trace == null"); + ASSERT((arguments.length === 1), + "arguments.length === 1"); if (debugging) { var context = this._peekContext(); this._traceParent = context; @@ -5920,12 +5900,7 @@ Promise.prototype._setTrace = function Promise$_setTrace(caller, parent) { this._trace = parent._trace; } else { - this._trace = new CapturedTrace( - typeof caller === "function" - ? caller - : this._setTrace, - isTopLevel - ); + this._trace = new CapturedTrace(isTopLevel); } } return this; @@ -6013,19 +5988,15 @@ Promise.prototype._settlePromiseAt = function Promise$_settlePromiseAt(index) { done = true; } else if (isPromiseArrayProxy(receiver, promise)) { - if (isFulfilled) receiver._promiseFulfilled(value, promise); else receiver._promiseRejected(value, promise); - done = true; } } if (!done) { - if (isFulfilled) promise._fulfill(value); else promise._reject(value, this._getCarriedStackTrace()); - } } @@ -6099,7 +6070,7 @@ function Promise$_fulfillUnchecked(value) { var len = this._length(); if (len > 0) { - async.invoke(this._fulfillPromises, this, len); + async.invoke(this._settlePromises, this, len); } }; @@ -6140,19 +6111,12 @@ function Promise$_rejectUnchecked(reason, trace) { }; Promise.prototype._rejectPromises = function Promise$_rejectPromises() { - ASSERT(this.isRejected(), - "this.isRejected()"); - var len = this._length(); - for (var i = 0; i < len; i+= 5) { - this._settlePromiseAt(i); - } + this._settlePromises(); this._unsetCarriedStackTrace(); }; -Promise.prototype._fulfillPromises = function Promise$_fulfillPromises(len) { - ASSERT(this.isFulfilled(), - "this.isFulfilled()"); - len = this._length(); +Promise.prototype._settlePromises = function Promise$_settlePromises() { + var len = this._length(); for (var i = 0; i < len; i+= 5) { this._settlePromiseAt(i); } @@ -6166,13 +6130,20 @@ function Promise$_ensurePossibleRejectionHandled() { } }; +Promise.prototype._notifyUnhandledRejectionIsHandled = +function Promise$_notifyUnhandledRejectionIsHandled() { + if (typeof unhandledRejectionHandled === "function") { + async.invokeLater(unhandledRejectionHandled, void 0, this); + } +}; + Promise.prototype._notifyUnhandledRejection = function Promise$_notifyUnhandledRejection() { if (this._isRejectionUnhandled()) { var reason = this._settledValue; var trace = this._getCarriedStackTrace(); - this._unsetRejectionIsUnhandled(); + this._setUnhandledRejectionIsNotified(); if (trace !== void 0) { this._unsetCarriedStackTrace(); @@ -6205,10 +6176,10 @@ Promise.prototype._popContext = function Promise$_popContext() { }; function Promise$_CreatePromiseArray( - promises, PromiseArrayConstructor, caller, boundTo) { + promises, PromiseArrayConstructor, boundTo) { - ASSERT((arguments.length === 4), - "arguments.length === 4"); + ASSERT((arguments.length === 3), + "arguments.length === 3"); ASSERT(((typeof PromiseArrayConstructor) === "function"), "typeof PromiseArrayConstructor === \u0022function\u0022"); @@ -6217,7 +6188,7 @@ function Promise$_CreatePromiseArray( list = promises; } else { - list = Promise._cast(promises, caller, void 0); + list = Promise._cast(promises, void 0); if (list !== promises) { list._setBoundTo(boundTo); } @@ -6226,13 +6197,7 @@ function Promise$_CreatePromiseArray( } } if (list !== null) { - return new PromiseArrayConstructor( - list, - typeof caller === "function" - ? caller - : Promise$_CreatePromiseArray, - boundTo - ); + return new PromiseArrayConstructor(list, boundTo); } return { promise: function() {return apiRejection("expecting an array, a promise or a thenable");} @@ -6240,7 +6205,6 @@ function Promise$_CreatePromiseArray( } var old = global.Promise; - Promise.noConflict = function() { if (global.Promise === Promise) { global.Promise = old; @@ -6257,6 +6221,7 @@ Promise._makeSelfResolutionError = makeSelfResolutionError; require("./finally.js")(Promise, NEXT_FILTER); require("./direct_resolve.js")(Promise); require("./thenables.js")(Promise, INTERNAL); +require("./synchronous_inspection.js")(Promise); Promise.RangeError = RangeError; Promise.CancellationError = CancellationError; Promise.TimeoutError = TimeoutError; @@ -6266,13 +6231,12 @@ Promise.RejectionError = RejectionError; util.toFastProperties(Promise); util.toFastProperties(Promise.prototype); require('./timers.js')(Promise,INTERNAL); -require('./synchronous_inspection.js')(Promise); require('./any.js')(Promise,Promise$_CreatePromiseArray,PromiseArray); require('./race.js')(Promise,INTERNAL); require('./call_get.js')(Promise); require('./filter.js')(Promise,Promise$_CreatePromiseArray,PromiseArray,apiRejection); require('./generators.js')(Promise,apiRejection,INTERNAL); -require('./map.js')(Promise,Promise$_CreatePromiseArray,PromiseArray,apiRejection); +require('./map.js')(Promise,PromiseArray,INTERNAL,apiRejection); require('./nodeify.js')(Promise); require('./promisify.js')(Promise,INTERNAL); require('./props.js')(Promise,PromiseArray); @@ -6287,7 +6251,7 @@ return Promise; }; -},{"./any.js":18,"./assert.js":19,"./async.js":20,"./call_get.js":22,"./cancel.js":23,"./captured_trace.js":24,"./catch_filter.js":25,"./direct_resolve.js":26,"./errors.js":27,"./errors_api_rejection":28,"./filter.js":30,"./finally.js":31,"./generators.js":32,"./global.js":33,"./map.js":34,"./nodeify.js":35,"./progress.js":36,"./promise_array.js":38,"./promise_resolver.js":40,"./promisify.js":42,"./props.js":44,"./race.js":46,"./reduce.js":47,"./settle.js":49,"./some.js":51,"./synchronous_inspection.js":53,"./thenables.js":54,"./timers.js":55,"./util.js":56,"__browserify_process":16}],38:[function(require,module,exports){ +},{"./any.js":18,"./assert.js":19,"./async.js":20,"./call_get.js":22,"./cancel.js":23,"./captured_trace.js":24,"./catch_filter.js":25,"./direct_resolve.js":26,"./errors.js":27,"./errors_api_rejection":28,"./filter.js":30,"./finally.js":31,"./generators.js":32,"./global.js":33,"./map.js":34,"./nodeify.js":35,"./progress.js":36,"./promise_array.js":38,"./promise_resolver.js":39,"./promisify.js":41,"./props.js":43,"./race.js":45,"./reduce.js":46,"./settle.js":48,"./some.js":50,"./synchronous_inspection.js":52,"./thenables.js":53,"./timers.js":54,"./util.js":55,"__browserify_process":16}],38:[function(require,module,exports){ /** * Copyright (c) 2014 Petka Antonov * @@ -6329,12 +6293,12 @@ function toResolutionValue(val) { "false"); } -function PromiseArray(values, caller, boundTo) { - ASSERT((arguments.length === 3), - "arguments.length === 3"); +function PromiseArray(values, boundTo) { + ASSERT((arguments.length === 2), + "arguments.length === 2"); var promise = this._promise = new Promise(INTERNAL); var parent = void 0; - if (Promise.is(values)) { + if (values instanceof Promise) { parent = values; if (values._cancellable()) { promise._setCancellable(); @@ -6344,7 +6308,7 @@ function PromiseArray(values, caller, boundTo) { promise._setBoundTo(boundTo); } } - promise._setTrace(caller, parent); + promise._setTrace(parent); this._values = values; this._length = 0; this._totalResolved = 0; @@ -6363,7 +6327,7 @@ PromiseArray.prototype.promise = function PromiseArray$promise() { PromiseArray.prototype._init = function PromiseArray$_init(_, resolveValueIfEmpty) { var values = this._values; - if (Promise.is(values)) { + if (values instanceof Promise) { if (values.isFulfilled()) { values = values._settledValue; if (!isArray(values)) { @@ -6383,8 +6347,7 @@ function PromiseArray$_init(_, resolveValueIfEmpty) { this._reject, void 0, this, - resolveValueIfEmpty, - this.constructor + resolveValueIfEmpty ); return; } @@ -6414,7 +6377,7 @@ function PromiseArray$_init(_, resolveValueIfEmpty) { newLen--; continue; } - var maybePromise = Promise._cast(promise, void 0, void 0); + var maybePromise = Promise._cast(promise, void 0); if (maybePromise instanceof Promise) { if (maybePromise.isPending()) { maybePromise._proxyPromiseArray(this, i); @@ -6451,7 +6414,7 @@ function PromiseArray$_init(_, resolveValueIfEmpty) { PromiseArray.prototype._settlePromiseAt = function PromiseArray$_settlePromiseAt(index) { var value = this._values[index]; - if (!Promise.is(value)) { + if (!(value instanceof Promise)) { this._promiseFulfilled(value, index); } else if (value.isFulfilled()) { @@ -6551,75 +6514,7 @@ function PromiseArray$_promiseRejected(reason, index) { return PromiseArray; }; -},{"./assert.js":19,"./async.js":20,"./errors.js":27,"./util.js":56}],39:[function(require,module,exports){ -/** - * Copyright (c) 2014 Petka Antonov - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions:

- * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - */ -"use strict"; -var TypeError = require("./errors.js").TypeError; - -function PromiseInspection(promise) { - if (promise !== void 0) { - this._bitField = promise._bitField; - this._settledValue = promise.isResolved() - ? promise._settledValue - : void 0; - } - else { - this._bitField = 0; - this._settledValue = void 0; - } -} -PromiseInspection.prototype.isFulfilled = -function PromiseInspection$isFulfilled() { - return (this._bitField & 268435456) > 0; -}; - -PromiseInspection.prototype.isRejected = -function PromiseInspection$isRejected() { - return (this._bitField & 134217728) > 0; -}; - -PromiseInspection.prototype.isPending = function PromiseInspection$isPending() { - return (this._bitField & 402653184) === 0; -}; - -PromiseInspection.prototype.value = function PromiseInspection$value() { - if (!this.isFulfilled()) { - throw new TypeError("cannot get fulfillment value of a non-fulfilled promise"); - } - return this._settledValue; -}; - -PromiseInspection.prototype.error = function PromiseInspection$error() { - if (!this.isRejected()) { - throw new TypeError("cannot get rejection reason of a non-rejected promise"); - } - return this._settledValue; -}; - -module.exports = PromiseInspection; - -},{"./errors.js":27}],40:[function(require,module,exports){ +},{"./assert.js":19,"./async.js":20,"./errors.js":27,"./util.js":55}],39:[function(require,module,exports){ /** * Copyright (c) 2014 Petka Antonov * @@ -6773,7 +6668,7 @@ function PromiseResolver$_setCarriedStackTrace(trace) { module.exports = PromiseResolver; -},{"./async.js":20,"./errors.js":27,"./es5.js":29,"./util.js":56}],41:[function(require,module,exports){ +},{"./async.js":20,"./errors.js":27,"./es5.js":29,"./util.js":55}],40:[function(require,module,exports){ /** * Copyright (c) 2014 Petka Antonov * @@ -6824,9 +6719,9 @@ function promiseFromYieldHandler(value) { return null; } -function PromiseSpawn(generatorFunction, receiver, caller) { +function PromiseSpawn(generatorFunction, receiver) { var promise = this._promise = new Promise(INTERNAL); - promise._setTrace(caller, void 0); + promise._setTrace(void 0); this._generatorFunction = generatorFunction; this._receiver = receiver; this._generator = void 0; @@ -6881,8 +6776,7 @@ PromiseSpawn.prototype._continue = function PromiseSpawn$_continue(result) { this._throw, void 0, this, - null, - void 0 + null ); } }; @@ -6909,7 +6803,7 @@ PromiseSpawn.addYieldHandler = function PromiseSpawn$AddYieldHandler(fn) { return PromiseSpawn; }; -},{"./assert.js":19,"./errors.js":27,"./util.js":56}],42:[function(require,module,exports){ +},{"./assert.js":19,"./errors.js":27,"./util.js":55}],41:[function(require,module,exports){ /** * Copyright (c) 2014 Petka Antonov * @@ -7100,7 +6994,7 @@ function makeNodePromisifiedEval(callback, receiver, originalName, fn) { "(" + parameterDeclaration(newParameterCount) + ") {\"use strict\";" + "var len = arguments.length;" + "var promise = new Promise(INTERNAL);"+ - "promise._setTrace(" + callbackName + ", void 0);" + + "promise._setTrace(void 0);" + "var fn = nodebackForPromise(promise);"+ "try {" + "switch(len) {" + @@ -7129,7 +7023,7 @@ function makeNodePromisifiedClosure(callback, receiver) { ASSERT(((typeof callback) === "function"), "typeof callback === \u0022function\u0022"); var promise = new Promise(INTERNAL); - promise._setTrace(promisified, void 0); + promise._setTrace(void 0); var fn = nodebackForPromise(promise); try { callback.apply(_receiver, withAppended(arguments, fn)); @@ -7196,7 +7090,7 @@ Promise.promisifyAll = function Promise$PromisifyAll(target) { }; -},{"./assert.js":19,"./es5.js":29,"./promise_resolver.js":40,"./util.js":56}],43:[function(require,module,exports){ +},{"./assert.js":19,"./es5.js":29,"./promise_resolver.js":39,"./util.js":55}],42:[function(require,module,exports){ /** * Copyright (c) 2014 Petka Antonov * @@ -7226,13 +7120,13 @@ var util = require("./util.js"); var inherits = util.inherits; var es5 = require("./es5.js"); -function PropertiesPromiseArray(obj, caller, boundTo) { +function PropertiesPromiseArray(obj, boundTo) { var keys = es5.keys(obj); var values = new Array(keys.length); for (var i = 0, len = values.length; i < len; ++i) { values[i] = obj[keys[i]]; } - this.constructor$(values, caller, boundTo); + this.constructor$(values, boundTo); if (!this._isResolved()) { for (var i = 0, len = keys.length; i < len; ++i) { values.push(keys[i]); @@ -7280,7 +7174,7 @@ PromiseArray.PropertiesPromiseArray = PropertiesPromiseArray; return PropertiesPromiseArray; }; -},{"./assert.js":19,"./es5.js":29,"./util.js":56}],44:[function(require,module,exports){ +},{"./assert.js":19,"./es5.js":29,"./util.js":55}],43:[function(require,module,exports){ /** * Copyright (c) 2014 Petka Antonov * @@ -7305,49 +7199,48 @@ return PropertiesPromiseArray; */ "use strict"; module.exports = function(Promise, PromiseArray) { - var PropertiesPromiseArray = require("./properties_promise_array.js")( - Promise, PromiseArray); - var util = require("./util.js"); - var apiRejection = require("./errors_api_rejection")(Promise); - var isObject = util.isObject; +var PropertiesPromiseArray = require("./properties_promise_array.js")( + Promise, PromiseArray); +var util = require("./util.js"); +var apiRejection = require("./errors_api_rejection")(Promise); +var isObject = util.isObject; - function Promise$_Props(promises, useBound, caller) { - var ret; - var castValue = Promise._cast(promises, caller, void 0); +function Promise$_Props(promises, useBound) { + var ret; + var castValue = Promise._cast(promises, void 0); - if (!isObject(castValue)) { - return apiRejection("cannot await properties of a non-object"); - } - else if (Promise.is(castValue)) { - ret = castValue._then(Promise.props, void 0, void 0, - void 0, void 0, caller); - } - else { - ret = new PropertiesPromiseArray( - castValue, - caller, - useBound === true && castValue._isBound() - ? castValue._boundTo - : void 0 - ).promise(); - useBound = false; - } - if (useBound === true && castValue._isBound()) { - ret._setBoundTo(castValue._boundTo); - } - return ret; + if (!isObject(castValue)) { + return apiRejection("cannot await properties of a non-object"); + } + else if (castValue instanceof Promise) { + ret = castValue._then(Promise.props, void 0, void 0, + void 0, void 0); + } + else { + ret = new PropertiesPromiseArray( + castValue, + useBound === true && castValue._isBound() + ? castValue._boundTo + : void 0 + ).promise(); + useBound = false; } + if (useBound === true && castValue._isBound()) { + ret._setBoundTo(castValue._boundTo); + } + return ret; +} - Promise.prototype.props = function Promise$props() { - return Promise$_Props(this, true, this.props); - }; +Promise.prototype.props = function Promise$props() { + return Promise$_Props(this, true); +}; - Promise.props = function Promise$Props(promises) { - return Promise$_Props(promises, false, Promise.props); - }; +Promise.props = function Promise$Props(promises) { + return Promise$_Props(promises, false); +}; }; -},{"./errors_api_rejection":28,"./properties_promise_array.js":43,"./util.js":56}],45:[function(require,module,exports){ +},{"./errors_api_rejection":28,"./properties_promise_array.js":42,"./util.js":55}],44:[function(require,module,exports){ /** * Copyright (c) 2014 Petka Antonov * @@ -7491,7 +7384,7 @@ Queue.prototype._resizeTo = function Queue$_resizeTo(capacity) { module.exports = Queue; -},{"./assert.js":19}],46:[function(require,module,exports){ +},{"./assert.js":19}],45:[function(require,module,exports){ /** * Copyright (c) 2014 Petka Antonov * @@ -7516,69 +7409,68 @@ module.exports = Queue; */ "use strict"; module.exports = function(Promise, INTERNAL) { - var apiRejection = require("./errors_api_rejection.js")(Promise); - var isArray = require("./util.js").isArray; +var apiRejection = require("./errors_api_rejection.js")(Promise); +var isArray = require("./util.js").isArray; - var raceLater = function Promise$_raceLater(promise) { - return promise.then(function Promise$_lateRacer(array) { - return Promise$_Race(array, Promise$_lateRacer, promise); - }); - }; +var raceLater = function Promise$_raceLater(promise) { + return promise.then(function(array) { + return Promise$_Race(array, promise); + }); +}; + +var hasOwn = {}.hasOwnProperty; +function Promise$_Race(promises, parent) { + var maybePromise = Promise._cast(promises, void 0); - var hasOwn = {}.hasOwnProperty; - function Promise$_Race(promises, caller, parent) { - var maybePromise = Promise._cast(promises, caller, void 0); + if (maybePromise instanceof Promise) { + return raceLater(maybePromise); + } + else if (!isArray(promises)) { + return apiRejection("expecting an array, a promise or a thenable"); + } - if (Promise.is(maybePromise)) { - return raceLater(maybePromise); + var ret = new Promise(INTERNAL); + ret._setTrace(parent); + if (parent !== void 0) { + if (parent._isBound()) { + ret._setBoundTo(parent._boundTo); } - else if (!isArray(promises)) { - return apiRejection("expecting an array, a promise or a thenable"); + if (parent._cancellable()) { + ret._setCancellable(); + ret._cancellationParent = parent; } + } + var fulfill = ret._fulfill; + var reject = ret._reject; + for (var i = 0, len = promises.length; i < len; ++i) { + var val = promises[i]; - var ret = new Promise(INTERNAL); - ret._setTrace(caller, parent); - if (parent !== void 0) { - if (parent._isBound()) { - ret._setBoundTo(parent._boundTo); - } - if (parent._cancellable()) { - ret._setCancellable(); - ret._cancellationParent = parent; - } + if (val === void 0 && !(hasOwn.call(promises, i))) { + continue; } - var fulfill = ret._fulfill; - var reject = ret._reject; - for (var i = 0, len = promises.length; i < len; ++i) { - var val = promises[i]; - if (val === void 0 && !(hasOwn.call(promises, i))) { - continue; - } - - Promise.cast(val)._then( - fulfill, - reject, - void 0, - ret, - null, - caller - ); - } - return ret; + Promise.cast(val)._then( + fulfill, + reject, + void 0, + ret, + null + ); } + return ret; +} - Promise.race = function Promise$Race(promises) { - return Promise$_Race(promises, Promise.race, void 0); - }; +Promise.race = function Promise$Race(promises) { + return Promise$_Race(promises, void 0); +}; - Promise.prototype.race = function Promise$race() { - return Promise$_Race(this, this.race, void 0); - }; +Promise.prototype.race = function Promise$race() { + return Promise$_Race(this, void 0); +}; }; -},{"./errors_api_rejection.js":28,"./util.js":56}],47:[function(require,module,exports){ +},{"./errors_api_rejection.js":28,"./util.js":55}],46:[function(require,module,exports){ /** * Copyright (c) 2014 Petka Antonov * @@ -7606,158 +7498,146 @@ module.exports = function( Promise, Promise$_CreatePromiseArray, PromiseArray, apiRejection, INTERNAL) { - var ASSERT = require("./assert.js"); +var ASSERT = require("./assert.js"); - function Reduction(callback, index, accum, items, receiver) { - this.promise = new Promise(INTERNAL); - this.index = index; - this.length = items.length; - this.items = items; - this.callback = callback; - this.receiver = receiver; - this.accum = accum; - } +function Reduction(callback, index, accum, items, receiver) { + this.promise = new Promise(INTERNAL); + this.index = index; + this.length = items.length; + this.items = items; + this.callback = callback; + this.receiver = receiver; + this.accum = accum; +} - Reduction.prototype.reject = function Reduction$reject(e) { - this.promise._reject(e); - }; +Reduction.prototype.reject = function Reduction$reject(e) { + this.promise._reject(e); +}; - Reduction.prototype.fulfill = function Reduction$fulfill(value, index) { - this.accum = value; - this.index = index + 1; - this.iterate(); - }; +Reduction.prototype.fulfill = function Reduction$fulfill(value, index) { + this.accum = value; + this.index = index + 1; + this.iterate(); +}; - Reduction.prototype.iterate = function Reduction$iterate() { - var i = this.index; - var len = this.length; - var items = this.items; - var result = this.accum; - var receiver = this.receiver; - var callback = this.callback; - var iterate = this.iterate; - - for(; i < len; ++i) { - result = Promise._cast( - callback.call( - receiver, - result, - items[i], - i, - len - ), - iterate, - void 0 - ); +Reduction.prototype.iterate = function Reduction$iterate() { + var i = this.index; + var len = this.length; + var items = this.items; + var result = this.accum; + var receiver = this.receiver; + var callback = this.callback; - if (result instanceof Promise) { - result._then( - this.fulfill, this.reject, void 0, this, i, iterate); - return; - } - } - this.promise._fulfill(result); - }; + for (; i < len; ++i) { + result = callback.call(receiver, result, items[i], i, len); + result = Promise._cast(result, void 0); - function Promise$_reducer(fulfilleds, initialValue) { - var fn = this; - var receiver = void 0; - if (typeof fn !== "function") { - receiver = fn.receiver; - fn = fn.fn; + if (result instanceof Promise) { + result._then( + this.fulfill, this.reject, void 0, this, i); + return; } - ASSERT(((typeof fn) === "function"), - "typeof fn === \u0022function\u0022"); - var len = fulfilleds.length; - var accum = void 0; - var startIndex = 0; + } + this.promise._fulfill(result); +}; - if (initialValue !== void 0) { - accum = initialValue; - startIndex = 0; - } - else { - startIndex = 1; - if (len > 0) accum = fulfilleds[0]; - } - var i = startIndex; +function Promise$_reducer(fulfilleds, initialValue) { + var fn = this; + var receiver = void 0; + if (typeof fn !== "function") { + receiver = fn.receiver; + fn = fn.fn; + } + ASSERT(((typeof fn) === "function"), + "typeof fn === \u0022function\u0022"); + var len = fulfilleds.length; + var accum = void 0; + var startIndex = 0; - if (i >= len) { - return accum; - } + if (initialValue !== void 0) { + accum = initialValue; + startIndex = 0; + } + else { + startIndex = 1; + if (len > 0) accum = fulfilleds[0]; + } + var i = startIndex; - var reduction = new Reduction(fn, i, accum, fulfilleds, receiver); - reduction.iterate(); - return reduction.promise; + if (i >= len) { + return accum; } - function Promise$_unpackReducer(fulfilleds) { - var fn = this.fn; - var initialValue = this.initialValue; - return Promise$_reducer.call(fn, fulfilleds, initialValue); + var reduction = new Reduction(fn, i, accum, fulfilleds, receiver); + reduction.iterate(); + return reduction.promise; +} + +function Promise$_unpackReducer(fulfilleds) { + var fn = this.fn; + var initialValue = this.initialValue; + return Promise$_reducer.call(fn, fulfilleds, initialValue); +} + +function Promise$_slowReduce( + promises, fn, initialValue, useBound) { + return initialValue._then(function(initialValue) { + return Promise$_Reduce( + promises, fn, initialValue, useBound); + }, void 0, void 0, void 0, void 0); +} + +function Promise$_Reduce(promises, fn, initialValue, useBound) { + if (typeof fn !== "function") { + return apiRejection("fn must be a function"); } - function Promise$_slowReduce( - promises, fn, initialValue, useBound, caller) { - return initialValue._then(function callee(initialValue) { - return Promise$_Reduce( - promises, fn, initialValue, useBound, callee); - }, void 0, void 0, void 0, void 0, caller); + if (useBound === true && promises._isBound()) { + fn = { + fn: fn, + receiver: promises._boundTo + }; } - function Promise$_Reduce(promises, fn, initialValue, useBound, caller) { - if (typeof fn !== "function") { - return apiRejection("fn must be a function"); + if (initialValue !== void 0) { + if (initialValue instanceof Promise) { + if (initialValue.isFulfilled()) { + initialValue = initialValue._settledValue; + } + else { + return Promise$_slowReduce(promises, + fn, initialValue, useBound); + } } - if (useBound === true && promises._isBound()) { - fn = { + return Promise$_CreatePromiseArray(promises, PromiseArray, + useBound === true && promises._isBound() + ? promises._boundTo + : void 0) + .promise() + ._then(Promise$_unpackReducer, void 0, void 0, { fn: fn, - receiver: promises._boundTo - }; - } - - if (initialValue !== void 0) { - if (Promise.is(initialValue)) { - if (initialValue.isFulfilled()) { - initialValue = initialValue._settledValue; - } - else { - return Promise$_slowReduce(promises, - fn, initialValue, useBound, caller); - } - } - - return Promise$_CreatePromiseArray(promises, PromiseArray, caller, - useBound === true && promises._isBound() - ? promises._boundTo - : void 0) - .promise() - ._then(Promise$_unpackReducer, void 0, void 0, { - fn: fn, - initialValue: initialValue - }, void 0, Promise.reduce); - } - return Promise$_CreatePromiseArray(promises, PromiseArray, caller, - useBound === true && promises._isBound() - ? promises._boundTo - : void 0).promise() - ._then(Promise$_reducer, void 0, void 0, fn, void 0, caller); + initialValue: initialValue + }, void 0); } + return Promise$_CreatePromiseArray(promises, PromiseArray, + useBound === true && promises._isBound() + ? promises._boundTo + : void 0).promise() + ._then(Promise$_reducer, void 0, void 0, fn, void 0); +} - Promise.reduce = function Promise$Reduce(promises, fn, initialValue) { - return Promise$_Reduce(promises, fn, - initialValue, false, Promise.reduce); - }; +Promise.reduce = function Promise$Reduce(promises, fn, initialValue) { + return Promise$_Reduce(promises, fn, initialValue, false); +}; - Promise.prototype.reduce = function Promise$reduce(fn, initialValue) { - return Promise$_Reduce(this, fn, initialValue, - true, this.reduce); - }; +Promise.prototype.reduce = function Promise$reduce(fn, initialValue) { + return Promise$_Reduce(this, fn, initialValue, true); +}; }; -},{"./assert.js":19}],48:[function(require,module,exports){ +},{"./assert.js":19}],47:[function(require,module,exports){ var process=require("__browserify_process");/** * Copyright (c) 2014 Petka Antonov * @@ -7893,7 +7773,7 @@ else { module.exports = schedule; -},{"./assert.js":19,"./global.js":33,"__browserify_process":16}],49:[function(require,module,exports){ +},{"./assert.js":19,"./global.js":33,"__browserify_process":16}],48:[function(require,module,exports){ /** * Copyright (c) 2014 Petka Antonov * @@ -7920,31 +7800,29 @@ module.exports = schedule; module.exports = function(Promise, Promise$_CreatePromiseArray, PromiseArray) { - var SettledPromiseArray = require("./settled_promise_array.js")( - Promise, PromiseArray); - - function Promise$_Settle(promises, useBound, caller) { - return Promise$_CreatePromiseArray( - promises, - SettledPromiseArray, - caller, - useBound === true && promises._isBound() - ? promises._boundTo - : void 0 - ).promise(); - } +var SettledPromiseArray = require("./settled_promise_array.js")( + Promise, PromiseArray); - Promise.settle = function Promise$Settle(promises) { - return Promise$_Settle(promises, false, Promise.settle); - }; +function Promise$_Settle(promises, useBound) { + return Promise$_CreatePromiseArray( + promises, + SettledPromiseArray, + useBound === true && promises._isBound() + ? promises._boundTo + : void 0 + ).promise(); +} - Promise.prototype.settle = function Promise$settle() { - return Promise$_Settle(this, true, this.settle); - }; +Promise.settle = function Promise$Settle(promises) { + return Promise$_Settle(promises, false); +}; +Promise.prototype.settle = function Promise$settle() { + return Promise$_Settle(this, true); +}; }; -},{"./settled_promise_array.js":50}],50:[function(require,module,exports){ +},{"./settled_promise_array.js":49}],49:[function(require,module,exports){ /** * Copyright (c) 2014 Petka Antonov * @@ -7970,11 +7848,11 @@ module.exports = "use strict"; module.exports = function(Promise, PromiseArray) { var ASSERT = require("./assert.js"); -var PromiseInspection = require("./promise_inspection.js"); +var PromiseInspection = Promise.PromiseInspection; var util = require("./util.js"); var inherits = util.inherits; -function SettledPromiseArray(values, caller, boundTo) { - this.constructor$(values, caller, boundTo); +function SettledPromiseArray(values, boundTo) { + this.constructor$(values, boundTo); } inherits(SettledPromiseArray, PromiseArray); @@ -8013,7 +7891,7 @@ function SettledPromiseArray$_promiseRejected(reason, index) { return SettledPromiseArray; }; -},{"./assert.js":19,"./promise_inspection.js":39,"./util.js":56}],51:[function(require,module,exports){ +},{"./assert.js":19,"./util.js":55}],50:[function(require,module,exports){ /** * Copyright (c) 2014 Petka Antonov * @@ -8040,43 +7918,42 @@ return SettledPromiseArray; module.exports = function(Promise, Promise$_CreatePromiseArray, PromiseArray, apiRejection) { - var SomePromiseArray = require("./some_promise_array.js")(PromiseArray); - var ASSERT = require("./assert.js"); +var SomePromiseArray = require("./some_promise_array.js")(PromiseArray); +var ASSERT = require("./assert.js"); - function Promise$_Some(promises, howMany, useBound, caller) { - if ((howMany | 0) !== howMany || howMany < 0) { - return apiRejection("expecting a positive integer"); - } - var ret = Promise$_CreatePromiseArray( - promises, - SomePromiseArray, - caller, - useBound === true && promises._isBound() - ? promises._boundTo - : void 0 - ); - var promise = ret.promise(); - if (promise.isRejected()) { - return promise; - } - ASSERT((ret instanceof SomePromiseArray), - "ret instanceof SomePromiseArray"); - ret.setHowMany(howMany); - ret.init(); +function Promise$_Some(promises, howMany, useBound) { + if ((howMany | 0) !== howMany || howMany < 0) { + return apiRejection("expecting a positive integer"); + } + var ret = Promise$_CreatePromiseArray( + promises, + SomePromiseArray, + useBound === true && promises._isBound() + ? promises._boundTo + : void 0 + ); + var promise = ret.promise(); + if (promise.isRejected()) { return promise; } + ASSERT((ret instanceof SomePromiseArray), + "ret instanceof SomePromiseArray"); + ret.setHowMany(howMany); + ret.init(); + return promise; +} - Promise.some = function Promise$Some(promises, howMany) { - return Promise$_Some(promises, howMany, false, Promise.some); - }; +Promise.some = function Promise$Some(promises, howMany) { + return Promise$_Some(promises, howMany, false); +}; - Promise.prototype.some = function Promise$some(count) { - return Promise$_Some(this, count, true, this.some); - }; +Promise.prototype.some = function Promise$some(count) { + return Promise$_Some(this, count, true); +}; }; -},{"./assert.js":19,"./some_promise_array.js":52}],52:[function(require,module,exports){ +},{"./assert.js":19,"./some_promise_array.js":51}],51:[function(require,module,exports){ /** * Copyright (c) 2014 Petka Antonov * @@ -8106,8 +7983,8 @@ var RangeError = require("./errors.js").RangeError; var inherits = util.inherits; var isArray = util.isArray; -function SomePromiseArray(values, caller, boundTo) { - this.constructor$(values, caller, boundTo); +function SomePromiseArray(values, boundTo) { + this.constructor$(values, boundTo); this._howMany = 0; this._unwrap = false; this._initialized = false; @@ -8209,7 +8086,7 @@ function SomePromiseArray$_canPossiblyFulfill() { return SomePromiseArray; }; -},{"./errors.js":27,"./util.js":56}],53:[function(require,module,exports){ +},{"./errors.js":27,"./util.js":55}],52:[function(require,module,exports){ /** * Copyright (c) 2014 Petka Antonov * @@ -8234,14 +8111,63 @@ return SomePromiseArray; */ "use strict"; module.exports = function(Promise) { - var PromiseInspection = require("./promise_inspection.js"); +function PromiseInspection(promise) { + if (promise !== void 0) { + this._bitField = promise._bitField; + this._settledValue = promise.isResolved() + ? promise._settledValue + : void 0; + } + else { + this._bitField = 0; + this._settledValue = void 0; + } +} + +PromiseInspection.prototype.isFulfilled = +Promise.prototype.isFulfilled = function Promise$isFulfilled() { + return (this._bitField & 268435456) > 0; +}; + +PromiseInspection.prototype.isRejected = +Promise.prototype.isRejected = function Promise$isRejected() { + return (this._bitField & 134217728) > 0; +}; + +PromiseInspection.prototype.isPending = +Promise.prototype.isPending = function Promise$isPending() { + return (this._bitField & 402653184) === 0; +}; + +PromiseInspection.prototype.value = +Promise.prototype.value = function Promise$value() { + if (!this.isFulfilled()) { + throw new TypeError("cannot get fulfillment value of a non-fulfilled promise"); + } + return this._settledValue; +}; - Promise.prototype.inspect = function Promise$inspect() { - return new PromiseInspection(this); - }; +PromiseInspection.prototype.error = +Promise.prototype.reason = function Promise$reason() { + if (!this.isRejected()) { + throw new TypeError("cannot get rejection reason of a non-rejected promise"); + } + return this._settledValue; +}; + +PromiseInspection.prototype.isResolved = +Promise.prototype.isResolved = function Promise$isResolved() { + return (this._bitField & 402653184) > 0; +}; + +Promise.prototype.inspect = function Promise$inspect() { + return new PromiseInspection(this); +}; + +Promise.PromiseInspection = PromiseInspection; }; -},{"./promise_inspection.js":39}],54:[function(require,module,exports){ +},{}],53:[function(require,module,exports){ /** * Copyright (c) 2014 Petka Antonov * @@ -8266,129 +8192,126 @@ module.exports = function(Promise) { */ "use strict"; 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; +var ASSERT = require("./assert.js"); +var util = require("./util.js"); +var canAttach = require("./errors.js").canAttach; +var errorObj = util.errorObj; +var isObject = util.isObject; - function getThen(obj) { - try { - return obj.then; - } - catch(e) { - errorObj.e = e; - return errorObj; - } +function getThen(obj) { + try { + return obj.then; + } + catch(e) { + errorObj.e = e; + return errorObj; } +} - function Promise$_Cast(obj, caller, originalPromise) { - ASSERT((arguments.length === 3), - "arguments.length === 3"); - if (isObject(obj)) { - if (obj instanceof Promise) { - return obj; - } - else if (isAnyBluebirdPromise(obj)) { - var ret = new Promise(INTERNAL); - ret._setTrace(caller, void 0); - obj._then( - ret._fulfillUnchecked, - ret._rejectUncheckedCheckError, - ret._progressUnchecked, - ret, - null, - void 0 - ); - ret._setFollowing(); - return ret; - } - var then = getThen(obj); - if (then === errorObj) { - caller = typeof caller === "function" ? caller : Promise$_Cast; - if (originalPromise !== void 0 && canAttach(then.e)) { - originalPromise._attachExtraTrace(then.e); - } - return Promise.reject(then.e, caller); - } - else if (typeof then === "function") { - caller = typeof caller === "function" ? caller : Promise$_Cast; - return Promise$_doThenable(obj, then, caller, originalPromise); +function Promise$_Cast(obj, originalPromise) { + ASSERT((arguments.length === 2), + "arguments.length === 2"); + if (isObject(obj)) { + if (obj instanceof Promise) { + return obj; + } + else if (isAnyBluebirdPromise(obj)) { + var ret = new Promise(INTERNAL); + ret._setTrace(void 0); + obj._then( + ret._fulfillUnchecked, + ret._rejectUncheckedCheckError, + ret._progressUnchecked, + ret, + null + ); + ret._setFollowing(); + return ret; + } + var then = getThen(obj); + if (then === errorObj) { + if (originalPromise !== void 0 && canAttach(then.e)) { + originalPromise._attachExtraTrace(then.e); } + return Promise.reject(then.e); + } + else if (typeof then === "function") { + return Promise$_doThenable(obj, then, originalPromise); } - return obj; } + return obj; +} - var hasProp = {}.hasOwnProperty; - function isAnyBluebirdPromise(obj) { - return hasProp.call(obj, "_promise0"); - } +var hasProp = {}.hasOwnProperty; +function isAnyBluebirdPromise(obj) { + return hasProp.call(obj, "_promise0"); +} - function Promise$_doThenable(x, then, caller, originalPromise) { - ASSERT(((typeof then) === "function"), +function Promise$_doThenable(x, then, originalPromise) { + ASSERT(((typeof then) === "function"), "typeof then === \u0022function\u0022"); - ASSERT((arguments.length === 4), - "arguments.length === 4"); - var resolver = Promise.defer(caller); - var called = false; - try { - then.call( - x, - Promise$_resolveFromThenable, - Promise$_rejectFromThenable, - Promise$_progressFromThenable - ); - } - catch(e) { - if (!called) { - called = true; - var trace = canAttach(e) ? e : new Error(e + ""); - if (originalPromise !== void 0) { - originalPromise._attachExtraTrace(trace); - } - resolver.promise._reject(e, trace); + ASSERT((arguments.length === 3), + "arguments.length === 3"); + var resolver = Promise.defer(); + var called = false; + try { + then.call( + x, + Promise$_resolveFromThenable, + Promise$_rejectFromThenable, + Promise$_progressFromThenable + ); + } + catch(e) { + if (!called) { + called = true; + var trace = canAttach(e) ? e : new Error(e + ""); + if (originalPromise !== void 0) { + originalPromise._attachExtraTrace(trace); } + resolver.promise._reject(e, trace); } - return resolver.promise; + } + return resolver.promise; - function Promise$_resolveFromThenable(y) { - if (called) return; - called = true; + function Promise$_resolveFromThenable(y) { + if (called) return; + called = true; - if (x === y) { - var e = Promise._makeSelfResolutionError(); - if (originalPromise !== void 0) { - originalPromise._attachExtraTrace(e); - } - resolver.promise._reject(e, void 0); - return; + if (x === y) { + var e = Promise._makeSelfResolutionError(); + if (originalPromise !== void 0) { + originalPromise._attachExtraTrace(e); } - resolver.resolve(y); + resolver.promise._reject(e, void 0); + return; } + resolver.resolve(y); + } - function Promise$_rejectFromThenable(r) { - if (called) return; - called = true; - var trace = canAttach(r) ? r : new Error(r + ""); - if (originalPromise !== void 0) { - originalPromise._attachExtraTrace(trace); - } - resolver.promise._reject(r, trace); + function Promise$_rejectFromThenable(r) { + if (called) return; + called = true; + var trace = canAttach(r) ? r : new Error(r + ""); + if (originalPromise !== void 0) { + originalPromise._attachExtraTrace(trace); } + resolver.promise._reject(r, trace); + } - function Promise$_progressFromThenable(v) { - if (called) return; - var promise = resolver.promise; - if (typeof promise._progress === "function") { - promise._progress(v); - } + function Promise$_progressFromThenable(v) { + if (called) return; + var promise = resolver.promise; + if (typeof promise._progress === "function") { + promise._progress(v); } } +} - Promise._cast = Promise$_Cast; +Promise._cast = Promise$_Cast; }; -},{"./assert.js":19,"./errors.js":27,"./util.js":56}],55:[function(require,module,exports){ +},{"./assert.js":19,"./errors.js":27,"./util.js":55}],54:[function(require,module,exports){ /** * Copyright (c) 2014 Petka Antonov * @@ -8412,100 +8335,89 @@ module.exports = function(Promise, INTERNAL) { * */ "use strict"; - var global = require("./global.js"); -var setTimeout = function(fn, time) { +var setTimeout = function(fn, ms) { var $_len = arguments.length;var args = new Array($_len - 2); for(var $_i = 2; $_i < $_len; ++$_i) {args[$_i - 2] = arguments[$_i];} - global.setTimeout(function() { + global.setTimeout(function(){ fn.apply(void 0, args); - }, time); + }, ms); }; -var pass = {}; -global.setTimeout( function(_) { - if(_ === pass) { - setTimeout = global.setTimeout; - } -}, 1, pass); - module.exports = function(Promise, INTERNAL) { - var util = require("./util.js"); - var ASSERT = require("./assert.js"); - var errors = require("./errors.js"); - var apiRejection = require("./errors_api_rejection")(Promise); - var TimeoutError = Promise.TimeoutError; - - var afterTimeout = function Promise$_afterTimeout(promise, message, ms) { - if (!promise.isPending()) return; - if (typeof message !== "string") { - message = "operation timed out after" + " " + ms + " ms" - } - var err = new TimeoutError(message); - errors.markAsOriginatingFromRejection(err); - promise._attachExtraTrace(err); - promise._rejectUnchecked(err); - }; +var util = require("./util.js"); +var ASSERT = require("./assert.js"); +var errors = require("./errors.js"); +var apiRejection = require("./errors_api_rejection")(Promise); +var TimeoutError = Promise.TimeoutError; - var afterDelay = function Promise$_afterDelay(value, promise) { - promise._fulfill(value); - }; +var afterTimeout = function Promise$_afterTimeout(promise, message, ms) { + if (!promise.isPending()) return; + if (typeof message !== "string") { + message = "operation timed out after" + " " + ms + " ms" + } + var err = new TimeoutError(message); + errors.markAsOriginatingFromRejection(err); + promise._attachExtraTrace(err); + promise._rejectUnchecked(err); +}; - Promise.delay = function Promise$Delay(value, ms, caller) { - if (ms === void 0) { - ms = value; - value = void 0; - } - ms = +ms; - if (typeof caller !== "function") { - caller = Promise.delay; - } - var maybePromise = Promise._cast(value, caller, void 0); - var promise = new Promise(INTERNAL); +var afterDelay = function Promise$_afterDelay(value, promise) { + promise._fulfill(value); +}; - if (Promise.is(maybePromise)) { - if (maybePromise._isBound()) { - promise._setBoundTo(maybePromise._boundTo); - } - if (maybePromise._cancellable()) { - promise._setCancellable(); - promise._cancellationParent = maybePromise; - } - promise._setTrace(caller, maybePromise); - promise._follow(maybePromise); - return promise.then(function(value) { - return Promise.delay(value, ms); - }); +var delay = Promise.delay = function Promise$Delay(value, ms) { + if (ms === void 0) { + ms = value; + value = void 0; + } + ms = +ms; + var maybePromise = Promise._cast(value, void 0); + var promise = new Promise(INTERNAL); + + if (maybePromise instanceof Promise) { + if (maybePromise._isBound()) { + promise._setBoundTo(maybePromise._boundTo); } - else { - promise._setTrace(caller, void 0); - setTimeout(afterDelay, ms, value, promise); + if (maybePromise._cancellable()) { + promise._setCancellable(); + promise._cancellationParent = maybePromise; } - return promise; - }; + promise._setTrace(maybePromise); + promise._follow(maybePromise); + return promise.then(function(value) { + return Promise.delay(value, ms); + }); + } + else { + promise._setTrace(void 0); + setTimeout(afterDelay, ms, value, promise); + } + return promise; +}; - Promise.prototype.delay = function Promise$delay(ms) { - return Promise.delay(this, ms, this.delay); - }; +Promise.prototype.delay = function Promise$delay(ms) { + return delay(this, ms); +}; - Promise.prototype.timeout = function Promise$timeout(ms, message) { - ms = +ms; +Promise.prototype.timeout = function Promise$timeout(ms, message) { + ms = +ms; - var ret = new Promise(INTERNAL); - ret._setTrace(this.timeout, this); + var ret = new Promise(INTERNAL); + ret._setTrace(this); - if (this._isBound()) ret._setBoundTo(this._boundTo); - if (this._cancellable()) { - ret._setCancellable(); - ret._cancellationParent = this; - } - ret._follow(this); - setTimeout(afterTimeout, ms, ret, message, ms); - return ret; - }; + if (this._isBound()) ret._setBoundTo(this._boundTo); + if (this._cancellable()) { + ret._setCancellable(); + ret._cancellationParent = this; + } + ret._follow(this); + setTimeout(afterTimeout, ms, ret, message, ms); + return ret; +}; }; -},{"./assert.js":19,"./errors.js":27,"./errors_api_rejection":28,"./global.js":33,"./util.js":56}],56:[function(require,module,exports){ +},{"./assert.js":19,"./errors.js":27,"./errors_api_rejection":28,"./global.js":33,"./util.js":55}],55:[function(require,module,exports){ /** * Copyright (c) 2014 Petka Antonov * @@ -8708,7 +8620,7 @@ var ret = { module.exports = ret; -},{"./assert.js":19,"./es5.js":29,"./global.js":33}],57:[function(require,module,exports){ +},{"./assert.js":19,"./es5.js":29,"./global.js":33}],56:[function(require,module,exports){ var process=require("__browserify_process");// vim:ts=4:sts=4:sw=4: /*! * @@ -10647,7 +10559,7 @@ return Q; }); -},{"__browserify_process":16}],58:[function(require,module,exports){ +},{"__browserify_process":16}],57:[function(require,module,exports){ /*jslint eqeqeq: false, onevar: false, forin: true, nomen: false, regexp: false, plusplus: false*/ /*global module, require, __dirname, document*/ /** @@ -11009,7 +10921,7 @@ var sinon = (function (buster) { return sinon; }(typeof buster == "object" && buster)); -},{"./sinon/assert":59,"./sinon/collection":60,"./sinon/match":61,"./sinon/mock":62,"./sinon/sandbox":63,"./sinon/spy":64,"./sinon/stub":65,"./sinon/test":66,"./sinon/test_case":67,"buster-format":69,"util":6}],59:[function(require,module,exports){ +},{"./sinon/assert":58,"./sinon/collection":59,"./sinon/match":60,"./sinon/mock":61,"./sinon/sandbox":62,"./sinon/spy":63,"./sinon/stub":64,"./sinon/test":65,"./sinon/test_case":66,"buster-format":68,"util":6}],58:[function(require,module,exports){ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {};/** * @depend ../sinon.js * @depend stub.js @@ -11194,7 +11106,7 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? } }(typeof sinon == "object" && sinon || null, typeof window != "undefined" ? window : (typeof self != "undefined") ? self : global)); -},{"../sinon":58}],60:[function(require,module,exports){ +},{"../sinon":57}],59:[function(require,module,exports){ /** * @depend ../sinon.js * @depend stub.js @@ -11349,7 +11261,7 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? } }(typeof sinon == "object" && sinon || null)); -},{"../sinon":58}],61:[function(require,module,exports){ +},{"../sinon":57}],60:[function(require,module,exports){ /* @depend ../sinon.js */ /*jslint eqeqeq: false, onevar: false, plusplus: false*/ /*global module, require, sinon*/ @@ -11590,7 +11502,7 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? } }(typeof sinon == "object" && sinon || null)); -},{"../sinon":58}],62:[function(require,module,exports){ +},{"../sinon":57}],61:[function(require,module,exports){ /** * @depend ../sinon.js * @depend stub.js @@ -12016,7 +11928,7 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? } }(typeof sinon == "object" && sinon || null)); -},{"../sinon":58}],63:[function(require,module,exports){ +},{"../sinon":57}],62:[function(require,module,exports){ /** * @depend ../sinon.js * @depend collection.js @@ -12143,7 +12055,7 @@ if (typeof module == "object" && typeof require == "function") { } }()); -},{"../sinon":58,"./util/fake_timers":68}],64:[function(require,module,exports){ +},{"../sinon":57,"./util/fake_timers":67}],63:[function(require,module,exports){ /** * @depend ../sinon.js * @depend match.js @@ -12723,7 +12635,7 @@ if (!this.sinon && commonJSModule) { } }(typeof sinon == "object" && sinon || null)); -},{"../sinon":58}],65:[function(require,module,exports){ +},{"../sinon":57}],64:[function(require,module,exports){ var process=require("__browserify_process");/** * @depend ../sinon.js * @depend spy.js @@ -13096,7 +13008,7 @@ var process=require("__browserify_process");/** } }(typeof sinon == "object" && sinon || null)); -},{"../sinon":58,"__browserify_process":16}],66:[function(require,module,exports){ +},{"../sinon":57,"__browserify_process":16}],65:[function(require,module,exports){ /** * @depend ../sinon.js * @depend stub.js @@ -13173,7 +13085,7 @@ var process=require("__browserify_process");/** } }(typeof sinon == "object" && sinon || null)); -},{"../sinon":58}],67:[function(require,module,exports){ +},{"../sinon":57}],66:[function(require,module,exports){ /** * @depend ../sinon.js * @depend test.js @@ -13272,7 +13184,7 @@ var process=require("__browserify_process");/** } }(typeof sinon == "object" && sinon || null)); -},{"../sinon":58}],68:[function(require,module,exports){ +},{"../sinon":57}],67:[function(require,module,exports){ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {};/*jslint eqeqeq: false, plusplus: false, evil: true, onevar: false, browser: true, forin: false*/ /*global module, require, window*/ /** @@ -13625,7 +13537,7 @@ if (typeof module == "object" && typeof require == "function") { module.exports = sinon; } -},{}],69:[function(require,module,exports){ +},{}],68:[function(require,module,exports){ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {};if (typeof buster === "undefined") { var buster = {}; } @@ -13826,7 +13738,7 @@ if (typeof module != "undefined") { module.exports = buster.format; } -},{"buster-core":70}],70:[function(require,module,exports){ +},{"buster-core":69}],69:[function(require,module,exports){ var process=require("__browserify_process");var buster = (function (setTimeout, B) { var isNode = typeof require == "function" && typeof module == "object"; var div = typeof document != "undefined" && document.createElement("div"); @@ -14051,7 +13963,7 @@ var process=require("__browserify_process");var buster = (function (setTimeout, return buster.extend(B || {}, buster); }(setTimeout, buster)); -},{"./buster-event-emitter":71,"./define-version-getter":72,"__browserify_process":16,"crypto":11,"path":5}],71:[function(require,module,exports){ +},{"./buster-event-emitter":70,"./define-version-getter":71,"__browserify_process":16,"crypto":11,"path":5}],70:[function(require,module,exports){ /*jslint eqeqeq: false, onevar: false, plusplus: false*/ /*global buster, require, module*/ if (typeof require == "function" && typeof module == "object") { @@ -14205,7 +14117,7 @@ if (typeof module != "undefined") { module.exports = buster.eventEmitter; } -},{"./buster-core":70}],72:[function(require,module,exports){ +},{"./buster-core":69}],71:[function(require,module,exports){ var path = require("path"); var fs = require("fs"); @@ -14223,7 +14135,7 @@ module.exports = function defineVersionGetter(mod, dirname) { }); }; -},{"fs":4,"path":5}],73:[function(require,module,exports){ +},{"fs":4,"path":5}],72:[function(require,module,exports){ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {};"use strict"; var assert = require("assert"); @@ -14301,7 +14213,7 @@ describe("2.1.2.1: When fulfilled, a promise: must not transition to any other s }); }); -},{"./helpers/testThreeCases":109,"assert":2}],74:[function(require,module,exports){ +},{"./helpers/testThreeCases":108,"assert":2}],73:[function(require,module,exports){ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {};"use strict"; var assert = require("assert"); @@ -14379,7 +14291,7 @@ describe("2.1.3.1: When rejected, a promise: must not transition to any other st }); }); -},{"./helpers/testThreeCases":109,"assert":2}],75:[function(require,module,exports){ +},{"./helpers/testThreeCases":108,"assert":2}],74:[function(require,module,exports){ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {};"use strict"; var adapter = global.adapter; @@ -14422,7 +14334,7 @@ describe("2.2.1: Both `onFulfilled` and `onRejected` are optional arguments.", f }); }); -},{}],76:[function(require,module,exports){ +},{}],75:[function(require,module,exports){ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {};"use strict"; var assert = require("assert"); @@ -14575,7 +14487,7 @@ describe("2.2.2: If `onFulfilled` is a function,", function () { }); }); -},{"./helpers/testThreeCases":109,"assert":2}],77:[function(require,module,exports){ +},{"./helpers/testThreeCases":108,"assert":2}],76:[function(require,module,exports){ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {};"use strict"; var assert = require("assert"); @@ -14728,7 +14640,7 @@ describe("2.2.3: If `onRejected` is a function,", function () { }); }); -},{"./helpers/testThreeCases":109,"assert":2}],78:[function(require,module,exports){ +},{"./helpers/testThreeCases":108,"assert":2}],77:[function(require,module,exports){ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {};"use strict"; var assert = require("assert"); @@ -14912,7 +14824,7 @@ describe("2.2.4: `onFulfilled` or `onRejected` must not be called until the exec }); }); -},{"./helpers/testThreeCases":109,"assert":2}],79:[function(require,module,exports){ +},{"./helpers/testThreeCases":108,"assert":2}],78:[function(require,module,exports){ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {};/*jshint strict: false */ var assert = require("assert"); @@ -14970,7 +14882,7 @@ describe("2.2.5 `onFulfilled` and `onRejected` must be called as functions (i.e. }); }); -},{"assert":2}],80:[function(require,module,exports){ +},{"assert":2}],79:[function(require,module,exports){ "use strict"; var assert = require("assert"); @@ -15229,7 +15141,7 @@ describe("2.2.6: `then` may be called multiple times on the same promise.", func }); }); -},{"./helpers/testThreeCases":109,"assert":2,"sinon":58}],81:[function(require,module,exports){ +},{"./helpers/testThreeCases":108,"assert":2,"sinon":57}],80:[function(require,module,exports){ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {};"use strict"; var assert = require("assert"); @@ -15340,7 +15252,7 @@ describe("2.2.7: `then` must return a promise: `promise2 = promise1.then(onFulfi }); }); -},{"./helpers/reasons":108,"./helpers/testThreeCases":109,"assert":2}],82:[function(require,module,exports){ +},{"./helpers/reasons":107,"./helpers/testThreeCases":108,"assert":2}],81:[function(require,module,exports){ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {};"use strict"; var assert = require("assert"); @@ -15376,7 +15288,7 @@ describe("2.3.1: If `promise` and `x` refer to the same object, reject `promise` }); }); -},{"assert":2}],83:[function(require,module,exports){ +},{"assert":2}],82:[function(require,module,exports){ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {};"use strict"; var assert = require("assert"); @@ -15504,7 +15416,7 @@ describe("2.3.2: If `x` is a promise, adopt its state", function () { }); }); -},{"assert":2}],84:[function(require,module,exports){ +},{"assert":2}],83:[function(require,module,exports){ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {};"use strict"; var assert = require("assert"); @@ -16499,7 +16411,7 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function () { }); }); -},{"./helpers/reasons":108,"./helpers/thenables":110,"assert":2}],85:[function(require,module,exports){ +},{"./helpers/reasons":107,"./helpers/thenables":109,"assert":2}],84:[function(require,module,exports){ "use strict"; var assert = require("assert"); @@ -16570,7 +16482,7 @@ describe("2.3.4: If `x` is not an object or function, fulfill `promise` with `x` ); }); -},{"./helpers/testThreeCases":109,"assert":2}],86:[function(require,module,exports){ +},{"./helpers/testThreeCases":108,"assert":2}],85:[function(require,module,exports){ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {};"use strict"; var adapter = global.adapter; @@ -16613,7 +16525,7 @@ describe("3.2.1: Both `onFulfilled` and `onRejected` are optional arguments.", f }); }); -},{}],87:[function(require,module,exports){ +},{}],86:[function(require,module,exports){ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {};"use strict"; var assert = require("assert"); @@ -16802,7 +16714,7 @@ describe("3.2.2: If `onFulfilled` is a function,", function () { }); }); -},{"./helpers/testThreeCases":109,"assert":2}],88:[function(require,module,exports){ +},{"./helpers/testThreeCases":108,"assert":2}],87:[function(require,module,exports){ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {};"use strict"; var assert = require("assert"); @@ -16991,7 +16903,7 @@ describe("3.2.3: If `onRejected` is a function,", function () { }); }); -},{"./helpers/testThreeCases":109,"assert":2}],89:[function(require,module,exports){ +},{"./helpers/testThreeCases":108,"assert":2}],88:[function(require,module,exports){ "use strict"; var assert = require("assert"); @@ -17024,7 +16936,7 @@ describe("3.2.4: `then` must return before `onFulfilled` or `onRejected` is call }); }); -},{"./helpers/testThreeCases":109,"assert":2}],90:[function(require,module,exports){ +},{"./helpers/testThreeCases":108,"assert":2}],89:[function(require,module,exports){ "use strict"; var assert = require("assert"); @@ -17283,7 +17195,7 @@ describe("3.2.5: `then` may be called multiple times on the same promise.", func }); }); -},{"./helpers/testThreeCases":109,"assert":2,"sinon":58}],91:[function(require,module,exports){ +},{"./helpers/testThreeCases":108,"assert":2,"sinon":57}],90:[function(require,module,exports){ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {};"use strict"; var assert = require("assert"); @@ -17606,7 +17518,7 @@ describe("3.2.6: `then` must return a promise: `promise2 = promise1.then(onFulfi }); }); -},{"./helpers/testThreeCases":109,"assert":2}],92:[function(require,module,exports){ +},{"./helpers/testThreeCases":108,"assert":2}],91:[function(require,module,exports){ "use strict"; var assert = require("assert"); @@ -17870,7 +17782,7 @@ if( Promise.hasLongStackTraces() ) { testCollection("props", function(){}); } -},{"../../js/debug/bluebird.js":21,"assert":2}],93:[function(require,module,exports){ +},{"../../js/debug/bluebird.js":21,"assert":2}],92:[function(require,module,exports){ "use strict"; var assert = require("assert"); @@ -18030,7 +17942,7 @@ describe("Async requirement", function() { }); } }); -},{"../../js/debug/bluebird.js":21,"assert":2}],94:[function(require,module,exports){ +},{"../../js/debug/bluebird.js":21,"assert":2}],93:[function(require,module,exports){ "use strict"; var assert = require("assert"); @@ -18967,7 +18879,7 @@ describe("When using .bind to gratuitously rebind", function(){ }); }); -},{"../../js/debug/bluebird.js":21,"assert":2}],95:[function(require,module,exports){ +},{"../../js/debug/bluebird.js":21,"assert":2}],94:[function(require,module,exports){ var process=require("__browserify_process");"use strict"; var isNodeJS = typeof process !== "undefined" && process !== null && @@ -19102,7 +19014,7 @@ if( isNodeJS ) { } -},{"../../js/debug/promise.js":37,"./helpers/bluebird0_7_0.js":107,"__browserify_process":16,"assert":2}],96:[function(require,module,exports){ +},{"../../js/debug/promise.js":37,"./helpers/bluebird0_7_0.js":106,"__browserify_process":16,"assert":2}],95:[function(require,module,exports){ /*global describe specify require global*/ //TODO include the copyright "use strict"; @@ -19113,7 +19025,9 @@ var adapter = require("../../js/debug/bluebird.js"); var fulfilled = adapter.fulfilled; var rejected = adapter.rejected; var pending = adapter.pending; - +var Promise = adapter; +var delay = Promise.delay; +var CancellationError = adapter.CancellationError; var sentinel = { sentinel: "sentinel" @@ -19123,10 +19037,15 @@ var dummy = { }; // we fulfill or reject with this when we don't intend to test against it function isCancellationError(error) { - return error instanceof Error && + return error instanceof CancellationError && error.name === "CancellationError"; } +function assertCancelled(promise) { + assert(promise.isRejected()); + assert(isCancellationError(promise.reason())); +} + describe("If the promise is not cancellable the 'cancel' call has no effect.", function() { specify("single-parent", function(done) { var parent = pending().promise.cancellable(); @@ -19196,7 +19115,7 @@ describe("Cancel.3: If the promise is pending and waiting on another promise the var parentCancelled = false; var tuple = pending(); var parent = tuple.promise.cancellable(); - parent.then(assert.fail, function(reason) { + var unhandled = parent.then(assert.fail, function(reason) { assert.ok(isCancellationError(reason)); parentCancelled = true; throw reason; @@ -19205,6 +19124,7 @@ describe("Cancel.3: If the promise is pending and waiting on another promise the assert.ok(isCancellationError(reason)); assert.ok(parentCancelled); done(); + unhandled.caught(function(){}); }) promise.cancel(); @@ -19218,30 +19138,23 @@ describe("Cancel.3: If the promise is pending and waiting on another promise the var tuple = pending(); var grandparent = tuple.promise.cancellable(); - var grandparentCancel = grandparent.cancel.bind(grandparent); - grandparent.cancel = function (arg) { - grandparentCancel(arg); - grandparentCancelled = true; - }; - grandparent.then(null, function(reason) { - assert.ok(isCancellationError(reason)); - uncleCancelled = true; + + var uncle = grandparent.then(null, function(reason) { throw reason; }); var parent = grandparent.then(assert.fail, function(reason) { - assert.ok(isCancellationError(reason)); - parentCancelled = true; throw reason; }); var promise = parent.then(assert.fail, function(reason) { assert.ok(isCancellationError(reason)); - assert.ok(parentCancelled); - assert.ok(uncleCancelled); - assert.ok(grandparentCancelled); + assertCancelled(parent); + assertCancelled(uncle); + assertCancelled(grandparent); done(); + uncle.caught(function(){}); }); assert(promise.isCancellable()); assert(parent.isCancellable()); @@ -19263,19 +19176,12 @@ describe("Cancel.4: Otherwise the promise is rejected with a CancellationError." }); specify("then fulfilled assumption", function(done) { - var assumedCancelled = false; var assumed = pending().promise.cancellable(); - var assumedCancel = assumed.cancel.bind(assumed); - assumed.cancel = function() { - assumedCancel(); - assumedCancelled = true; - }; - var promise = fulfilled().cancellable().then(function() { return assumed; }).then(assert.fail, function(reason) { assert.ok(isCancellationError(reason)); - assert.ok(assumedCancelled); + assertCancelled(assumed); done(); }); @@ -19283,17 +19189,13 @@ describe("Cancel.4: Otherwise the promise is rejected with a CancellationError." }); specify("then rejected assumption", function(done) { - var assumedCancelled = false; var assumed = pending().promise.cancellable(); - assumed.then(null, function(reason) { - assert.ok(isCancellationError(reason)); - assumedCancelled = true; - }); + var promise = rejected().cancellable().then(null, function() { return assumed; }).then(assert.fail, function(reason) { assert.ok(isCancellationError(reason)); - assert.ok(assumedCancelled); + assertCancelled(assumed); done(); }); @@ -19302,13 +19204,7 @@ describe("Cancel.4: Otherwise the promise is rejected with a CancellationError." specify("then chain-fulfilled assumption", function(done) { - var assumedCancelled = false; var assumed = pending().promise.cancellable(); - var assumedCancel = assumed.cancel.bind(assumed); - assumed.cancel = function() { - assumedCancel(); - assumedCancelled = true; - }; var promise = fulfilled().cancellable().then(function() { return fulfilled(); @@ -19316,7 +19212,7 @@ describe("Cancel.4: Otherwise the promise is rejected with a CancellationError." return assumed; }).then(assert.fail, function(reason) { assert.ok(isCancellationError(reason)); - assert.ok(assumedCancelled); + assertCancelled(assumed); done(); }); @@ -19325,29 +19221,61 @@ describe("Cancel.4: Otherwise the promise is rejected with a CancellationError." specify("then chain-rejected assumption", function(done) { - var assumedCancelled = false; var assumed = pending().promise.cancellable(); - var assumedCancel = assumed.cancel.bind(assumed); - assumed.cancel = function() { - assumedCancel(); - assumedCancelled = true; - }; - var promise = rejected().cancellable().then(null, function() { return rejected(); }).then(null, function() { return assumed; }).then(assert.fail, function(reason) { assert.ok(isCancellationError(reason)); - assert.ok(assumedCancelled); + assertCancelled(assumed); done(); }); promise.cancel(); }); }); +describe("issues", function(){ + specify("gh-166", function(done) { + var f1 = false, f2 = false, f3 = false, f4 = false; + var a = Promise.resolve().cancellable(); + a = a.then(function() { + f1 = true; + return delay(35); + }); -},{"../../js/debug/bluebird.js":21,"assert":2}],97:[function(require,module,exports){ + a = a.then(function() { + f2 = true; + return delay(35); + }); + + a = a.then(function() { + f3 = true; + return delay(300); + }); + + a = a.then(function() { + f4 = true; + }); + + var waitingForLongDelay = a; + + a = a.caught(Promise.CancellationError, function() { + assert(f1); assert(f2); assert(f3); + assertCancelled(waitingForLongDelay); + assert(!f4); + done(); + }); + + assert(a.isCancellable()); + setTimeout(function() { + assert(a.isCancellable()); + a.cancel(); + }, 100); + }); +}); + +},{"../../js/debug/bluebird.js":21,"assert":2}],96:[function(require,module,exports){ "use strict"; var assert = require("assert"); @@ -19751,7 +19679,7 @@ describe("A promise handler with a predicate filter", function() { }); -},{"../../js/debug/bluebird.js":21,"assert":2}],98:[function(require,module,exports){ +},{"../../js/debug/bluebird.js":21,"assert":2}],97:[function(require,module,exports){ "use strict"; var assert = require("assert"); @@ -20152,7 +20080,7 @@ describe("Using collection methods with thenables", function() { }, filterer); }); -},{"../../js/debug/bluebird.js":21,"assert":2}],99:[function(require,module,exports){ +},{"../../js/debug/bluebird.js":21,"assert":2}],98:[function(require,module,exports){ "use strict"; var assert = require("assert"); @@ -20367,7 +20295,7 @@ describe("Promise constructor", function() { }); -},{"../../js/debug/bluebird.js":21,"assert":2}],100:[function(require,module,exports){ +},{"../../js/debug/bluebird.js":21,"assert":2}],99:[function(require,module,exports){ "use strict"; var assert = require("assert"); @@ -20442,7 +20370,7 @@ describe("Cyclical promises should throw TypeError when", function(){ }); }); -},{"../../js/debug/bluebird.js":21,"./helpers/testThreeCases.js":109,"assert":2}],101:[function(require,module,exports){ +},{"../../js/debug/bluebird.js":21,"./helpers/testThreeCases.js":108,"assert":2}],100:[function(require,module,exports){ "use strict"; @@ -20618,7 +20546,7 @@ describe("thenThrow", function () { }); }); -},{"../../js/debug/bluebird.js":21,"./helpers/testThreeCases.js":109,"assert":2}],102:[function(require,module,exports){ +},{"../../js/debug/bluebird.js":21,"./helpers/testThreeCases.js":108,"assert":2}],101:[function(require,module,exports){ var process=require("__browserify_process");"use strict"; var assert = require("assert"); @@ -20655,7 +20583,7 @@ if (isNodeJS) { }); } -},{"../../js/debug/bluebird.js":21,"__browserify_process":16,"assert":2,"domain":3}],103:[function(require,module,exports){ +},{"../../js/debug/bluebird.js":21,"__browserify_process":16,"assert":2,"domain":3}],102:[function(require,module,exports){ "use strict"; var assert = require("assert"); @@ -20788,7 +20716,7 @@ describe("Promise.prototype.error", function(){ }); }) -},{"../../js/debug/bluebird.js":21,"assert":2}],104:[function(require,module,exports){ +},{"../../js/debug/bluebird.js":21,"assert":2}],103:[function(require,module,exports){ "use strict"; var assert = require("assert"); @@ -20918,7 +20846,7 @@ describe("Promise filter", function() { }); }); -},{"../../js/debug/bluebird.js":21,"assert":2}],105:[function(require,module,exports){ +},{"../../js/debug/bluebird.js":21,"assert":2}],104:[function(require,module,exports){ "use strict"; var assert = require("assert"); @@ -21039,7 +20967,7 @@ describe("Rejecting a promise A with promise B", function(){ }); }); -},{"../../js/debug/bluebird.js":21,"assert":2}],106:[function(require,module,exports){ +},{"../../js/debug/bluebird.js":21,"assert":2}],105:[function(require,module,exports){ "use strict"; var assert = require("assert"); @@ -21106,7 +21034,7 @@ describe("github36", function(){ }); -},{"../../js/debug/bluebird.js":21,"assert":2}],107:[function(require,module,exports){ +},{"../../js/debug/bluebird.js":21,"assert":2}],106:[function(require,module,exports){ var process=require("__browserify_process");/* jshint -W014, -W116, -W106 */ /* global process, unreachable */ /** @@ -22202,8 +22130,6 @@ function Promise$_then( internalData, caller ) { - ASSERT((arguments.length === 6), - "arguments.length === 6"); var haveInternalData = internalData !== void 0; var ret = haveInternalData ? internalData : new Promise(); @@ -23382,7 +23308,7 @@ return Promise;})( Object ); -},{"__browserify_process":16}],108:[function(require,module,exports){ +},{"__browserify_process":16}],107:[function(require,module,exports){ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {};"use strict"; // This module exports some valid rejection reason factories, keyed by human-readable versions of their names. @@ -23440,7 +23366,7 @@ exports["a rejected promise"] = function () { return rejected(dummy); }; -},{}],109:[function(require,module,exports){ +},{}],108:[function(require,module,exports){ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {};"use strict"; var adapter = global.adapter; @@ -23488,7 +23414,7 @@ exports.testRejected = function (reason, test) { }); }; -},{}],110:[function(require,module,exports){ +},{}],109:[function(require,module,exports){ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {};"use strict"; var adapter = global.adapter; @@ -23634,7 +23560,7 @@ exports.rejected = { } }; -},{}],111:[function(require,module,exports){ +},{}],110:[function(require,module,exports){ var process=require("__browserify_process");"use strict"; var assert = require("assert"); @@ -23684,7 +23610,7 @@ if( isNodeJS ) { }); }); } -},{"../../js/debug/bluebird.js":21,"__browserify_process":16,"assert":2}],112:[function(require,module,exports){ +},{"../../js/debug/bluebird.js":21,"__browserify_process":16,"assert":2}],111:[function(require,module,exports){ "use strict"; var assert = require("assert"); @@ -23791,7 +23717,7 @@ describe("Promise.method", function(){ }); }); -},{"../../js/debug/bluebird.js":21,"assert":2}],113:[function(require,module,exports){ +},{"../../js/debug/bluebird.js":21,"assert":2}],112:[function(require,module,exports){ "use strict"; var assert = require("assert"); @@ -24482,7 +24408,7 @@ if (canTestArity) { }) } -},{"../../js/debug/bluebird.js":21,"assert":2}],114:[function(require,module,exports){ +},{"../../js/debug/bluebird.js":21,"assert":2}],113:[function(require,module,exports){ var assert = require("assert"); var adapter = require("../../js/debug/bluebird.js"); @@ -24757,7 +24683,7 @@ describe("Promise.props", function () { }); -},{"../../js/debug/bluebird.js":21,"assert":2}],115:[function(require,module,exports){ +},{"../../js/debug/bluebird.js":21,"assert":2}],114:[function(require,module,exports){ var assert = require("assert"); var adapter = require("../../js/debug/bluebird.js"); @@ -24923,7 +24849,7 @@ describe("all", function () { }); -},{"../../js/debug/bluebird.js":21,"assert":2}],116:[function(require,module,exports){ +},{"../../js/debug/bluebird.js":21,"assert":2}],115:[function(require,module,exports){ var process=require("__browserify_process");var assert = require("assert"); var adapter = require("../../js/debug/bluebird.js"); @@ -25207,7 +25133,7 @@ describe("done", function () { }); -},{"../../js/debug/bluebird.js":21,"__browserify_process":16,"assert":2,"sinon":58}],117:[function(require,module,exports){ +},{"../../js/debug/bluebird.js":21,"__browserify_process":16,"assert":2,"sinon":57}],116:[function(require,module,exports){ var assert = require("assert"); var adapter = require("../../js/debug/bluebird.js"); @@ -25546,7 +25472,7 @@ describe("finally", function () { }); }); -},{"../../js/debug/bluebird.js":21,"assert":2}],118:[function(require,module,exports){ +},{"../../js/debug/bluebird.js":21,"assert":2}],117:[function(require,module,exports){ var assert = require("assert"); var adapter = require("../../js/debug/bluebird.js"); @@ -25672,7 +25598,7 @@ describe("inspect", function () { }); -},{"../../js/debug/bluebird.js":21,"assert":2}],119:[function(require,module,exports){ +},{"../../js/debug/bluebird.js":21,"assert":2}],118:[function(require,module,exports){ var assert = require("assert"); var adapter = require("../../js/debug/bluebird.js"); @@ -25733,7 +25659,7 @@ describe("PromiseResolver.callback", function () { }); -},{"../../js/debug/bluebird.js":21,"assert":2}],120:[function(require,module,exports){ +},{"../../js/debug/bluebird.js":21,"assert":2}],119:[function(require,module,exports){ var process=require("__browserify_process");var assert = require("assert"); var adapter = require("../../js/debug/bluebird.js"); @@ -25922,7 +25848,7 @@ if( isNodeJS ) { }); } -},{"../../js/debug/bluebird.js":21,"__browserify_process":16,"assert":2,"sinon":58}],121:[function(require,module,exports){ +},{"../../js/debug/bluebird.js":21,"__browserify_process":16,"assert":2,"sinon":57}],120:[function(require,module,exports){ var assert = require("assert"); var adapter = require("../../js/debug/bluebird.js"); @@ -26380,7 +26306,7 @@ describe("progress", function () { }); }); -},{"../../js/debug/bluebird.js":21,"assert":2}],122:[function(require,module,exports){ +},{"../../js/debug/bluebird.js":21,"assert":2}],121:[function(require,module,exports){ var assert = require("assert"); var adapter = require("../../js/debug/bluebird.js"); @@ -26598,7 +26524,7 @@ describe("propagation", function () { }); }); -},{"../../js/debug/bluebird.js":21,"assert":2}],123:[function(require,module,exports){ +},{"../../js/debug/bluebird.js":21,"assert":2}],122:[function(require,module,exports){ var assert = require("assert"); var adapter = require("../../js/debug/bluebird.js"); @@ -26745,7 +26671,7 @@ describe("allSettled", function () { }); -},{"../../js/debug/bluebird.js":21,"assert":2}],124:[function(require,module,exports){ +},{"../../js/debug/bluebird.js":21,"assert":2}],123:[function(require,module,exports){ var assert = require("assert"); var adapter = require("../../js/debug/bluebird.js"); @@ -27039,7 +26965,7 @@ describe("spread", function () { }); -},{"../../js/debug/bluebird.js":21,"assert":2}],125:[function(require,module,exports){ +},{"../../js/debug/bluebird.js":21,"assert":2}],124:[function(require,module,exports){ "use strict"; var assert = require("assert"); @@ -27178,7 +27104,7 @@ describe("Promise.race", function(){ }); }); -},{"../../js/debug/bluebird.js":21,"assert":2}],126:[function(require,module,exports){ +},{"../../js/debug/bluebird.js":21,"assert":2}],125:[function(require,module,exports){ "use strict"; var assert = require("assert"); @@ -27263,7 +27189,7 @@ describe("Promise.prototype.reduce", function() { }); }); -},{"../../js/debug/bluebird.js":21,"assert":2}],127:[function(require,module,exports){ +},{"../../js/debug/bluebird.js":21,"assert":2}],126:[function(require,module,exports){ "use strict"; var assert = require("assert"); @@ -27424,7 +27350,7 @@ describe("Implicitly cast thenable", function() { }); }); -},{"../../js/debug/bluebird.js":21,"assert":2}],128:[function(require,module,exports){ +},{"../../js/debug/bluebird.js":21,"assert":2}],127:[function(require,module,exports){ "use strict"; var assert = require("assert"); @@ -27492,7 +27418,7 @@ describe("If promise is reused to get at the value many times over the course of }); }); -},{"../../js/debug/bluebird.js":21,"assert":2}],129:[function(require,module,exports){ +},{"../../js/debug/bluebird.js":21,"assert":2}],128:[function(require,module,exports){ var process=require("__browserify_process");var assert = require("assert"); var schedule = require("../../js/debug/schedule"); var isNodeJS = typeof process !== "undefined" && typeof process.execPath === "string"; @@ -27517,7 +27443,7 @@ describe("schedule", function () { } }); -},{"../../js/debug/schedule":48,"__browserify_process":16,"assert":2,"domain":3}],130:[function(require,module,exports){ +},{"../../js/debug/schedule":47,"__browserify_process":16,"assert":2,"domain":3}],129:[function(require,module,exports){ "use strict"; var assert = require("assert"); @@ -27570,7 +27496,7 @@ describe("Promise.some", function(){ }); }); -},{"../../js/debug/bluebird.js":21,"assert":2}],131:[function(require,module,exports){ +},{"../../js/debug/bluebird.js":21,"assert":2}],130:[function(require,module,exports){ "use strict"; var assert = require("assert"); @@ -27642,7 +27568,7 @@ describe("When using a sparse array the resulting array should have equal sparsi }); -},{"../../js/debug/bluebird.js":21,"assert":2}],132:[function(require,module,exports){ +},{"../../js/debug/bluebird.js":21,"assert":2}],131:[function(require,module,exports){ var assert = require("assert"); var adapter = require("../../js/debug/bluebird.js"); @@ -27712,7 +27638,7 @@ describe("tap", function () { }); }); -},{"../../js/debug/bluebird.js":21,"assert":2}],133:[function(require,module,exports){ +},{"../../js/debug/bluebird.js":21,"assert":2}],132:[function(require,module,exports){ var assert = require("assert"); var adapter = require("../../js/debug/bluebird.js"); @@ -27874,7 +27800,7 @@ describe("delay", function () { }); }); -},{"../../js/debug/bluebird.js":21,"assert":2}],134:[function(require,module,exports){ +},{"../../js/debug/bluebird.js":21,"assert":2}],133:[function(require,module,exports){ "use strict"; var assert = require("assert"); @@ -27981,7 +27907,7 @@ describe("Promise.try", function(){ }); }); -},{"../../js/debug/bluebird.js":21,"assert":2}],135:[function(require,module,exports){ +},{"../../js/debug/bluebird.js":21,"assert":2}],134:[function(require,module,exports){ "use strict"; var assert = require("assert"); var Promise = require("../../js/debug/bluebird.js"); @@ -28589,6 +28515,38 @@ describe("gh-118", function() { }); }); +describe("Promise.onUnhandledRejectionHandled", function() { + specify("should be called when unhandled promise is later handled", function(done) { + var unhandledPromises = []; + Promise.onPossiblyUnhandledRejection(function(reason, promise) { + unhandledPromises.push({ + reason: reason, + promise: promise + }); + }); + + Promise.onUnhandledRejectionHandled(function(promise) { + assert.equal(unhandledPromises.length, 1); + assert(unhandledPromises[0].promise === promise); + assert(promise === a); + assert(unhandledPromises[0].reason === reason); + Promise.onUnhandledRejectionHandled(null); + Promise.onPossiblyUnhandledRejection(null); + done(); + }); + + var reason = new Error("error"); + var a = new Promise(function(){ + throw reason; + }); + setTimeout(function(){ + a.caught(function(){ + + }); + }, 25); + }); +}); + if (Promise.hasLongStackTraces()) { describe("Gives long stack traces for non-errors", function() { @@ -28700,7 +28658,7 @@ describe("clear unhandled handler", function() { Promise.onPossiblyUnhandledRejection(null); }); -},{"../../js/debug/bluebird.js":21,"./helpers/bluebird0_7_0.js":107,"assert":2,"q":57}],136:[function(require,module,exports){ +},{"../../js/debug/bluebird.js":21,"./helpers/bluebird0_7_0.js":106,"assert":2,"q":56}],135:[function(require,module,exports){ /* Based on When.js tests @@ -28817,7 +28775,7 @@ describe("when.all-test", function () { }); -},{"../../js/debug/bluebird.js":21,"assert":2}],137:[function(require,module,exports){ +},{"../../js/debug/bluebird.js":21,"assert":2}],136:[function(require,module,exports){ /* Based on When.js tests @@ -28961,7 +28919,7 @@ describe("when.any-test", function () { }); }); -},{"../../js/debug/bluebird.js":21,"assert":2}],138:[function(require,module,exports){ +},{"../../js/debug/bluebird.js":21,"assert":2}],137:[function(require,module,exports){ /* Based on When.js tests @@ -29489,7 +29447,7 @@ describe("when.defer-test", function () { }); }); -},{"../../js/debug/bluebird.js":21,"assert":2}],139:[function(require,module,exports){ +},{"../../js/debug/bluebird.js":21,"assert":2}],138:[function(require,module,exports){ /* Based on When.js tests @@ -29626,7 +29584,7 @@ describe("when.join-test", function () { }); -},{"../../js/debug/bluebird.js":21,"assert":2}],140:[function(require,module,exports){ +},{"../../js/debug/bluebird.js":21,"assert":2}],139:[function(require,module,exports){ /* Based on When.js tests @@ -29838,7 +29796,6 @@ describe("when.map-test", function () { } //This test didn't contain the mapper argument so I assume //when.js uses identity mapper in such cases. - //In bluebird it's illegal to call Promise.map without mapper function return when.map(input, identity).then(function () { assert(ncall === 6); @@ -29869,9 +29826,50 @@ describe("when.map-test", function () { }); + function delay(val, ms) { + return new when(function(resolve) { + setTimeout(function() { + resolve(val); + }, ms); + }); + } + + specify("should be concurrent but process in-order", function(done) { + var firstProcessed = false; + var secondProcessed = false; + var thirdProcessed = false; + + var first = delay(1, 20); + var second = delay(2, 100).then(function(){secondProcessed = true}); + var third = delay(3, 100).then(function(){thirdProcessed = true}); + + when.map([first, second, third], function(integer) { + if (integer === 1) { + return delay(0, 10).then(function() { + assert(!secondProcessed); + assert(!thirdProcessed); + return delay(0, 10); + }).then(function() { + assert(!secondProcessed); + assert(!thirdProcessed); + return delay(0, 10); + }).then(function(){ + firstProcessed = true; + }); + } + else { + assert(firstProcessed); + } + }).then(function() { + assert(firstProcessed); + assert(secondProcessed); + assert(thirdProcessed); + done(); + }); + }); }); -},{"../../js/debug/bluebird.js":21,"assert":2}],141:[function(require,module,exports){ +},{"../../js/debug/bluebird.js":21,"assert":2}],140:[function(require,module,exports){ /* Based on When.js tests @@ -30123,7 +30121,7 @@ describe("when.reduce-test", function () { }); }); -},{"../../js/debug/bluebird.js":21,"assert":2}],142:[function(require,module,exports){ +},{"../../js/debug/bluebird.js":21,"assert":2}],141:[function(require,module,exports){ /* Based on When.js tests @@ -30289,7 +30287,7 @@ describe("when.settle-test", function () { }); }); -},{"../../js/debug/bluebird.js":21,"assert":2}],143:[function(require,module,exports){ +},{"../../js/debug/bluebird.js":21,"assert":2}],142:[function(require,module,exports){ /* Based on When.js tests @@ -30516,7 +30514,7 @@ describe("when.some-test", function () { }); }); -},{"../../js/debug/bluebird.js":21,"assert":2}],144:[function(require,module,exports){ +},{"../../js/debug/bluebird.js":21,"assert":2}],143:[function(require,module,exports){ /* Based on When.js tests diff --git a/js/browser/bluebird.js b/js/browser/bluebird.js index 4085eed86..9c85cf8db 100644 --- a/js/browser/bluebird.js +++ b/js/browser/bluebird.js @@ -1,6 +1,6 @@ /** - * bluebird build version 1.1.1 - * Features enabled: core, timers, race, any, call_get, filter, generators, map, nodeify, promisify, props, reduce, settle, some, progress, cancel, synchronous_inspection + * bluebird build version 1.2.0 + * Features enabled: core, timers, race, any, call_get, filter, generators, map, nodeify, promisify, props, reduce, settle, some, progress, cancel */ /** * @preserve Copyright (c) 2014 Petka Antonov @@ -50,37 +50,36 @@ "use strict"; module.exports = function(Promise, Promise$_CreatePromiseArray, PromiseArray) { - var SomePromiseArray = require("./some_promise_array.js")(PromiseArray); - function Promise$_Any(promises, useBound, caller) { - var ret = Promise$_CreatePromiseArray( - promises, - SomePromiseArray, - caller, - useBound === true && promises._isBound() - ? promises._boundTo - : void 0 - ); - var promise = ret.promise(); - if (promise.isRejected()) { - return promise; - } - ret.setHowMany(1); - ret.setUnwrap(); - ret.init(); +var SomePromiseArray = require("./some_promise_array.js")(PromiseArray); +function Promise$_Any(promises, useBound) { + var ret = Promise$_CreatePromiseArray( + promises, + SomePromiseArray, + useBound === true && promises._isBound() + ? promises._boundTo + : void 0 + ); + var promise = ret.promise(); + if (promise.isRejected()) { return promise; } + ret.setHowMany(1); + ret.setUnwrap(); + ret.init(); + return promise; +} - Promise.any = function Promise$Any(promises) { - return Promise$_Any(promises, false, Promise.any); - }; +Promise.any = function Promise$Any(promises) { + return Promise$_Any(promises, false); +}; - Promise.prototype.any = function Promise$any() { - return Promise$_Any(this, true, this.any); - }; +Promise.prototype.any = function Promise$any() { + return Promise$_Any(this, true); +}; }; -},{"./some_promise_array.js":34}],2:[function(require,module,exports){ +},{"./some_promise_array.js":33}],2:[function(require,module,exports){ /** * Copyright (c) 2014 Petka Antonov * @@ -193,7 +192,7 @@ Async.prototype._reset = function Async$_reset() { module.exports = new Async(); -},{"./global.js":15,"./queue.js":27,"./schedule.js":30,"./util.js":38}],3:[function(require,module,exports){ +},{"./global.js":15,"./queue.js":26,"./schedule.js":29,"./util.js":37}],3:[function(require,module,exports){ /** * Copyright (c) 2014 Petka Antonov * @@ -244,36 +243,34 @@ module.exports = Promise; */ "use strict"; module.exports = function(Promise) { - Promise.prototype.call = function Promise$call(propertyName) { - var $_len = arguments.length;var args = new Array($_len - 1); for(var $_i = 1; $_i < $_len; ++$_i) {args[$_i - 1] = arguments[$_i];} - - return this._then(function(obj) { - return obj[propertyName].apply(obj, args); - }, - void 0, - void 0, - void 0, - void 0, - this.call - ); - }; +Promise.prototype.call = function Promise$call(propertyName) { + var $_len = arguments.length;var args = new Array($_len - 1); for(var $_i = 1; $_i < $_len; ++$_i) {args[$_i - 1] = arguments[$_i];} + + return this._then(function(obj) { + return obj[propertyName].apply(obj, args); + }, + void 0, + void 0, + void 0, + void 0 + ); +}; - function Promise$getter(obj) { - var prop = typeof this === "string" - ? this - : ("" + this); - return obj[prop]; - } - Promise.prototype.get = function Promise$get(propertyName) { - return this._then( - Promise$getter, - void 0, - void 0, - propertyName, - void 0, - this.get - ); - }; +function Promise$getter(obj) { + var prop = typeof this === "string" + ? this + : ("" + this); + return obj[prop]; +} +Promise.prototype.get = function Promise$get(propertyName) { + return this._then( + Promise$getter, + void 0, + void 0, + propertyName, + void 0 + ); +}; }; },{}],5:[function(require,module,exports){ @@ -301,58 +298,54 @@ module.exports = function(Promise) { */ "use strict"; module.exports = function(Promise, INTERNAL) { - var errors = require("./errors.js"); - var async = require("./async.js"); - var CancellationError = errors.CancellationError; - var SYNC_TOKEN = {}; - - Promise.prototype._cancel = function Promise$_cancel() { - if (!this.isCancellable()) return this; - var parent; - if ((parent = this._cancellationParent) !== void 0) { - parent.cancel(SYNC_TOKEN); - return; - } - var err = new CancellationError(); - this._attachExtraTrace(err); - this._rejectUnchecked(err); - }; +var errors = require("./errors.js"); +var async = require("./async.js"); +var CancellationError = errors.CancellationError; - Promise.prototype.cancel = function Promise$cancel(token) { - if (!this.isCancellable()) return this; - if (token === SYNC_TOKEN) { - this._cancel(); - return this; - } - async.invokeLater(this._cancel, this, void 0); - return this; - }; +Promise.prototype._cancel = function Promise$_cancel() { + if (!this.isCancellable()) return this; + var parent; + var promiseToReject = this; + while ((parent = promiseToReject._cancellationParent) !== void 0 && + parent.isCancellable()) { + promiseToReject = parent; + } + var err = new CancellationError(); + promiseToReject._attachExtraTrace(err); + promiseToReject._rejectUnchecked(err); +}; - Promise.prototype.cancellable = function Promise$cancellable() { - if (this._cancellable()) return this; - this._setCancellable(); - this._cancellationParent = void 0; - return this; - }; +Promise.prototype.cancel = function Promise$cancel() { + if (!this.isCancellable()) return this; + async.invokeLater(this._cancel, this, void 0); + return this; +}; - Promise.prototype.uncancellable = function Promise$uncancellable() { - var ret = new Promise(INTERNAL); - ret._setTrace(this.uncancellable, this); - ret._follow(this); - ret._unsetCancellable(); - if (this._isBound()) ret._setBoundTo(this._boundTo); - return ret; - }; +Promise.prototype.cancellable = function Promise$cancellable() { + if (this._cancellable()) return this; + this._setCancellable(); + this._cancellationParent = void 0; + return this; +}; + +Promise.prototype.uncancellable = function Promise$uncancellable() { + var ret = new Promise(INTERNAL); + ret._setTrace(this); + ret._follow(this); + ret._unsetCancellable(); + if (this._isBound()) ret._setBoundTo(this._boundTo); + return ret; +}; - Promise.prototype.fork = - function Promise$fork(didFulfill, didReject, didProgress) { - var ret = this._then(didFulfill, didReject, didProgress, - void 0, void 0, this.fork); +Promise.prototype.fork = +function Promise$fork(didFulfill, didReject, didProgress) { + var ret = this._then(didFulfill, didReject, didProgress, + void 0, void 0); - ret._setCancellable(); - ret._cancellationParent = void 0; - return ret; - }; + ret._setCancellable(); + ret._cancellationParent = void 0; + return ret; +}; }; },{"./async.js":2,"./errors.js":9}],6:[function(require,module,exports){ @@ -384,7 +377,7 @@ var inherits = require("./util.js").inherits; var defineProperty = require("./es5.js").defineProperty; var rignore = new RegExp( - "\\b(?:[\\w.]*Promise(?:Array|Spawn)?\\$_\\w+|" + + "\\b(?:[a-zA-Z0-9.]+\\$_\\w+|" + "tryCatch(?:1|2|Apply)|new \\w*PromiseArray|" + "\\w*PromiseArray\\.\\w*PromiseArray|" + "setTimeout|CatchFilter\\$_\\w+|makeNodePromisified|processImmediate|" + @@ -393,7 +386,6 @@ var rignore = new RegExp( var rtraceline = null; var formatStack = null; -var areNamesMangled = false; function formatNonError(obj) { var str; @@ -430,9 +422,7 @@ function snip(str) { } function CapturedTrace(ignoreUntil, isTopLevel) { - if (!areNamesMangled) { - } - this.captureStackTrace(ignoreUntil, isTopLevel); + this.captureStackTrace(CapturedTrace, isTopLevel); } inherits(CapturedTrace, Error); @@ -458,15 +448,12 @@ function CapturedTrace$PossiblyUnhandledRejection(reason) { console.error(message); } else if (typeof console.log === "function" || - typeof console.error === "object") { + typeof console.log === "object") { console.log(message); } } }; -areNamesMangled = CapturedTrace.prototype.captureStackTrace.name !== - "CapturedTrace$captureStackTrace"; - CapturedTrace.combine = function CapturedTrace$Combine(current, prev) { var curLast = current.length - 1; for (var i = prev.length - 1; i >= 0; --i) { @@ -485,7 +472,6 @@ CapturedTrace.combine = function CapturedTrace$Combine(current, prev) { var ret = []; - for (var i = 0, len = lines.length; i < len; ++i) { if ((rignore.test(lines[i]) || @@ -526,7 +512,7 @@ var captureStackTrace = (function stackDetection() { } var err = new Error(); - if (!areNamesMangled && typeof err.stack === "string" && + if (typeof err.stack === "string" && typeof "".startsWith === "function" && (err.stack.startsWith("stackDetection@")) && stackDetection.name === "stackDetection") { @@ -552,20 +538,12 @@ var captureStackTrace = (function stackDetection() { return formatNonError(error); }; - return function captureStackTrace(o, fn) { - var name = fn.name; + return function captureStackTrace(o) { var stack = new Error().stack; var split = stack.split(rline); - var i, len = split.length; - for (i = 0; i < len; i += 2) { - if (split[i] === name) { - break; - } - } - split = split.slice(i + 2); - len = split.length - 2; + var len = split.length; var ret = ""; - for (i = 0; i < len; i += 2) { + for (var i = 0; i < len; i += 2) { ret += split[i]; ret += "@"; ret += split[i + 1]; @@ -594,7 +572,7 @@ var captureStackTrace = (function stackDetection() { return CapturedTrace; }; -},{"./es5.js":11,"./util.js":38}],7:[function(require,module,exports){ +},{"./es5.js":11,"./util.js":37}],7:[function(require,module,exports){ /** * Copyright (c) 2014 Petka Antonov * @@ -624,6 +602,7 @@ var errors = require("./errors.js"); var tryCatch1 = util.tryCatch1; var errorObj = util.errorObj; var keys = require("./es5.js").keys; +var TypeError = errors.TypeError; function CatchFilter(instances, callback, promise) { this._instances = instances; @@ -689,7 +668,7 @@ CatchFilter.prototype.doFilter = function CatchFilter$_doFilter(e) { return CatchFilter; }; -},{"./errors.js":9,"./es5.js":11,"./util.js":38}],8:[function(require,module,exports){ +},{"./errors.js":9,"./es5.js":11,"./util.js":37}],8:[function(require,module,exports){ /** * Copyright (c) 2014 Petka Antonov * @@ -748,12 +727,10 @@ function Promise$thenReturn(value) { void 0, void 0, void 0, - void 0, - this.thenReturn + void 0 ); } - return this._then(returner, void 0, void 0, - value, void 0, this.thenReturn); + return this._then(returner, void 0, void 0, value, void 0); }; Promise.prototype["throw"] = @@ -765,16 +742,14 @@ function Promise$thenThrow(reason) { void 0, void 0, void 0, - void 0, - this.thenThrow + void 0 ); } - return this._then(thrower, void 0, void 0, - reason, void 0, this.thenThrow); + return this._then(thrower, void 0, void 0, reason, void 0); }; }; -},{"./util.js":38}],9:[function(require,module,exports){ +},{"./util.js":37}],9:[function(require,module,exports){ /** * Copyright (c) 2014 Petka Antonov * @@ -890,7 +865,7 @@ module.exports = { canAttach: canAttach }; -},{"./es5.js":11,"./global.js":15,"./util.js":38}],10:[function(require,module,exports){ +},{"./es5.js":11,"./global.js":15,"./util.js":37}],10:[function(require,module,exports){ /** * Copyright (c) 2014 Petka Antonov * @@ -1046,37 +1021,35 @@ else { */ "use strict"; module.exports = function(Promise) { - var isArray = require("./util.js").isArray; +var isArray = require("./util.js").isArray; - function Promise$_filter(booleans) { - var values = this._settledValue; - var len = values.length; - var ret = new Array(len); - var j = 0; +function Promise$_filter(booleans) { + var values = this instanceof Promise ? this._settledValue : this; + var len = values.length; + var ret = new Array(len); + var j = 0; - for (var i = 0; i < len; ++i) { - if (booleans[i]) ret[j++] = values[i]; + for (var i = 0; i < len; ++i) { + if (booleans[i]) ret[j++] = values[i]; - } - ret.length = j; - return ret; } + ret.length = j; + return ret; +} - var ref = {ref: null}; - Promise.filter = function Promise$Filter(promises, fn) { - return Promise.map(promises, fn, ref) - ._then(Promise$_filter, void 0, void 0, - ref.ref, void 0, Promise.filter); - }; +var ref = {ref: null}; +Promise.filter = function Promise$Filter(promises, fn) { + return Promise.map(promises, fn, ref) + ._then(Promise$_filter, void 0, void 0, ref.ref, void 0); +}; - Promise.prototype.filter = function Promise$filter(fn) { - return this.map(fn, ref) - ._then(Promise$_filter, void 0, void 0, - ref.ref, void 0, this.filter); - }; +Promise.prototype.filter = function Promise$filter(fn) { + return this.map(fn, ref) + ._then(Promise$_filter, void 0, void 0, ref.ref, void 0); +}; }; -},{"./util.js":38}],13:[function(require,module,exports){ +},{"./util.js":37}],13:[function(require,module,exports){ /** * Copyright (c) 2014 Petka Antonov * @@ -1101,116 +1074,107 @@ module.exports = function(Promise) { */ "use strict"; module.exports = function(Promise, NEXT_FILTER) { - var util = require("./util.js"); - var wrapsPrimitiveReceiver = util.wrapsPrimitiveReceiver; - var isPrimitive = util.isPrimitive; - var thrower = util.thrower; +var util = require("./util.js"); +var wrapsPrimitiveReceiver = util.wrapsPrimitiveReceiver; +var isPrimitive = util.isPrimitive; +var thrower = util.thrower; - function returnThis() { - return this; - } - function throwThis() { - throw this; - } - function makeReturner(r) { - return function Promise$_returner() { - return r; - }; - } - function makeThrower(r) { - return function Promise$_thrower() { - throw r; - }; +function returnThis() { + return this; +} +function throwThis() { + throw this; +} +function return$(r) { + return function Promise$_returner() { + return r; + }; +} +function throw$(r) { + return function Promise$_thrower() { + throw r; + }; +} +function promisedFinally(ret, reasonOrValue, isFulfilled) { + var then; + if (wrapsPrimitiveReceiver && isPrimitive(reasonOrValue)) { + then = isFulfilled ? return$(reasonOrValue) : throw$(reasonOrValue); } - function promisedFinally(ret, reasonOrValue, isFulfilled) { - var useConstantFunction = - wrapsPrimitiveReceiver && isPrimitive(reasonOrValue); - - if (isFulfilled) { - return ret._then( - useConstantFunction - ? returnThis - : makeReturner(reasonOrValue), - thrower, void 0, reasonOrValue, void 0, promisedFinally); - } - else { - return ret._then( - useConstantFunction - ? throwThis - : makeThrower(reasonOrValue), - thrower, void 0, reasonOrValue, void 0, promisedFinally); - } + else { + then = isFulfilled ? returnThis : throwThis; } + return ret._then(then, thrower, void 0, reasonOrValue, void 0); +} - function finallyHandler(reasonOrValue) { - var promise = this.promise; - var handler = this.handler; +function finallyHandler(reasonOrValue) { + var promise = this.promise; + var handler = this.handler; - var ret = promise._isBound() - ? handler.call(promise._boundTo) - : handler(); + var ret = promise._isBound() + ? handler.call(promise._boundTo) + : handler(); - if (ret !== void 0) { - var maybePromise = Promise._cast(ret, finallyHandler, void 0); - if (maybePromise instanceof Promise) { - return promisedFinally(maybePromise, reasonOrValue, - promise.isFulfilled()); - } + if (ret !== void 0) { + var maybePromise = Promise._cast(ret, void 0); + if (maybePromise instanceof Promise) { + return promisedFinally(maybePromise, reasonOrValue, + promise.isFulfilled()); } + } - if (promise.isRejected()) { - NEXT_FILTER.e = reasonOrValue; - return NEXT_FILTER; - } - else { - return reasonOrValue; - } + if (promise.isRejected()) { + NEXT_FILTER.e = reasonOrValue; + return NEXT_FILTER; + } + else { + return reasonOrValue; } +} - function tapHandler(value) { - var promise = this.promise; - var handler = this.handler; +function tapHandler(value) { + var promise = this.promise; + var handler = this.handler; - var ret = promise._isBound() - ? handler.call(promise._boundTo, value) - : handler(value); + var ret = promise._isBound() + ? handler.call(promise._boundTo, value) + : handler(value); - if (ret !== void 0) { - var maybePromise = Promise._cast(ret, tapHandler, void 0); - if (maybePromise instanceof Promise) { - return promisedFinally(maybePromise, value, true); - } + if (ret !== void 0) { + var maybePromise = Promise._cast(ret, void 0); + if (maybePromise instanceof Promise) { + return promisedFinally(maybePromise, value, true); } - return value; } + return value; +} - Promise.prototype._passThroughHandler = - function Promise$_passThroughHandler(handler, isFinally, caller) { - if (typeof handler !== "function") return this.then(); - - var promiseAndHandler = { - promise: this, - handler: handler - }; +Promise.prototype._passThroughHandler = +function Promise$_passThroughHandler(handler, isFinally) { + if (typeof handler !== "function") return this.then(); - return this._then( - isFinally ? finallyHandler : tapHandler, - isFinally ? finallyHandler : void 0, void 0, - promiseAndHandler, void 0, caller); + var promiseAndHandler = { + promise: this, + handler: handler }; - Promise.prototype.lastly = - Promise.prototype["finally"] = function Promise$finally(handler) { - return this._passThroughHandler(handler, true, this.lastly); - }; + return this._then( + isFinally ? finallyHandler : tapHandler, + isFinally ? finallyHandler : void 0, void 0, + promiseAndHandler, void 0); +}; - Promise.prototype.tap = function Promise$tap(handler) { - return this._passThroughHandler(handler, false, this.tap); - }; +Promise.prototype.lastly = +Promise.prototype["finally"] = function Promise$finally(handler) { + return this._passThroughHandler(handler, true); +}; + +Promise.prototype.tap = function Promise$tap(handler) { + return this._passThroughHandler(handler, false); +}; }; -},{"./util.js":38}],14:[function(require,module,exports){ +},{"./util.js":37}],14:[function(require,module,exports){ /** * Copyright (c) 2014 Petka Antonov * @@ -1235,40 +1199,40 @@ module.exports = function(Promise, NEXT_FILTER) { */ "use strict"; module.exports = function(Promise, apiRejection, INTERNAL) { - var PromiseSpawn = require("./promise_spawn.js")(Promise, INTERNAL); - var errors = require("./errors.js"); - var TypeError = errors.TypeError; - var deprecated = require("./util.js").deprecated; - - Promise.coroutine = function Promise$Coroutine(generatorFunction) { - if (typeof generatorFunction !== "function") { - throw new TypeError("generatorFunction must be a function"); - } - var PromiseSpawn$ = PromiseSpawn; - return function anonymous() { - var generator = generatorFunction.apply(this, arguments); - var spawn = new PromiseSpawn$(void 0, void 0, anonymous); - spawn._generator = generator; - spawn._next(void 0); - return spawn.promise(); - }; +var PromiseSpawn = require("./promise_spawn.js")(Promise, INTERNAL); +var errors = require("./errors.js"); +var TypeError = errors.TypeError; +var deprecated = require("./util.js").deprecated; + +Promise.coroutine = function Promise$Coroutine(generatorFunction) { + if (typeof generatorFunction !== "function") { + throw new TypeError("generatorFunction must be a function"); + } + var PromiseSpawn$ = PromiseSpawn; + return function () { + var generator = generatorFunction.apply(this, arguments); + var spawn = new PromiseSpawn$(void 0, void 0); + spawn._generator = generator; + spawn._next(void 0); + return spawn.promise(); }; +}; - Promise.coroutine.addYieldHandler = PromiseSpawn.addYieldHandler; +Promise.coroutine.addYieldHandler = PromiseSpawn.addYieldHandler; - Promise.spawn = function Promise$Spawn(generatorFunction) { - deprecated("Promise.spawn is deprecated. Use Promise.coroutine instead."); - if (typeof generatorFunction !== "function") { - return apiRejection("generatorFunction must be a function"); - } - var spawn = new PromiseSpawn(generatorFunction, this, Promise.spawn); - var ret = spawn.promise(); - spawn._run(Promise.spawn); - return ret; - }; +Promise.spawn = function Promise$Spawn(generatorFunction) { + deprecated("Promise.spawn is deprecated. Use Promise.coroutine instead."); + if (typeof generatorFunction !== "function") { + return apiRejection("generatorFunction must be a function"); + } + var spawn = new PromiseSpawn(generatorFunction, this); + var ret = spawn.promise(); + spawn._run(Promise.spawn); + return ret; +}; }; -},{"./errors.js":9,"./promise_spawn.js":23,"./util.js":38}],15:[function(require,module,exports){ +},{"./errors.js":9,"./promise_spawn.js":22,"./util.js":37}],15:[function(require,module,exports){ /** * Copyright (c) 2014 Petka Antonov * @@ -1293,23 +1257,23 @@ module.exports = function(Promise, apiRejection, INTERNAL) { */ "use strict"; module.exports = (function(){ - if (typeof this !== "undefined") { - return this; - } - if (typeof process !== "undefined" && - typeof global !== "undefined" && - typeof process.execPath === "string") { - return global; - } - if (typeof window !== "undefined" && - typeof document !== "undefined" && - typeof navigator !== "undefined" && navigator !== null && - typeof navigator.appName === "string") { - if(window.wrappedJSObject !== undefined){ - return window.wrappedJSObject; - } - return window; - } +if (typeof this !== "undefined") { + return this; +} +if (typeof process !== "undefined" && + typeof global !== "undefined" && + typeof process.execPath === "string") { + return global; +} +if (typeof window !== "undefined" && + typeof document !== "undefined" && + typeof navigator !== "undefined" && navigator !== null && + typeof navigator.appName === "string") { + if(window.wrappedJSObject !== undefined){ + return window.wrappedJSObject; + } + return window; +} })(); },{}],16:[function(require,module,exports){ @@ -1336,112 +1300,161 @@ module.exports = (function(){ * */ "use strict"; -module.exports = function( - Promise, Promise$_CreatePromiseArray, PromiseArray, apiRejection) { +module.exports = function(Promise, PromiseArray, INTERNAL, apiRejection) { + +var all = Promise.all; +var util = require("./util.js"); +var canAttach = require("./errors.js").canAttach; +var isArray = util.isArray; +var _cast = Promise._cast; + +function unpack(values) { + return Promise$_Map(values, this[0], this[1], this[2]); +} - function Promise$_mapper(values) { - var fn = this; - var receiver = void 0; +function Promise$_Map(promises, fn, useBound, ref) { + if (typeof fn !== "function") { + return apiRejection("fn must be a function"); + } - if (typeof fn !== "function") { - receiver = fn.receiver; - fn = fn.fn; + var receiver = void 0; + if (useBound === true) { + if (promises._isBound()) { + receiver = promises._boundTo; } - var shouldDefer = false; - - var ret = new Array(values.length); - - if (receiver === void 0) { - for (var i = 0, len = values.length; i < len; ++i) { - var value = fn(values[i], i, len); - if (!shouldDefer) { - var maybePromise = Promise._cast(value, - Promise$_mapper, void 0); - if (maybePromise instanceof Promise) { - if (maybePromise.isFulfilled()) { - ret[i] = maybePromise._settledValue; - continue; - } - else { - shouldDefer = true; - } - value = maybePromise; - } + } + else if (useBound !== false) { + receiver = useBound; + } + + var shouldUnwrapItems = ref !== void 0; + if (shouldUnwrapItems) ref.ref = promises; + + if (promises instanceof Promise) { + var pack = [fn, receiver, ref]; + return promises._then(unpack, void 0, void 0, pack, void 0); + } + else if (!isArray(promises)) { + return apiRejection("expecting an array, a promise or a thenable"); + } + + var promise = new Promise(INTERNAL); + if (receiver !== void 0) promise._setBoundTo(receiver); + promise._setTrace(void 0); + + var mapping = new Mapping(promise, + fn, + promises, + receiver, + shouldUnwrapItems); + mapping.init(); + return promise; +} + +var pending = {}; +function Mapping(promise, callback, items, receiver, shouldUnwrapItems) { + this.shouldUnwrapItems = shouldUnwrapItems; + this.index = 0; + this.items = items; + this.callback = callback; + this.receiver = receiver; + this.promise = promise; + this.result = new Array(items.length); +} +util.inherits(Mapping, PromiseArray); + +Mapping.prototype.init = function Mapping$init() { + var items = this.items; + var len = items.length; + var result = this.result; + var isRejected = false; + for (var i = 0; i < len; ++i) { + var maybePromise = _cast(items[i], void 0); + if (maybePromise instanceof Promise) { + if (maybePromise.isPending()) { + result[i] = pending; + maybePromise._proxyPromiseArray(this, i); + } + else if (maybePromise.isFulfilled()) { + result[i] = maybePromise.value(); + } + else { + maybePromise._unsetRejectionIsUnhandled(); + if (!isRejected) { + this.reject(maybePromise.reason()); + isRejected = true; } - ret[i] = value; } } else { - for (var i = 0, len = values.length; i < len; ++i) { - var value = fn.call(receiver, values[i], i, len); - if (!shouldDefer) { - var maybePromise = Promise._cast(value, - Promise$_mapper, void 0); - if (maybePromise instanceof Promise) { - if (maybePromise.isFulfilled()) { - ret[i] = maybePromise._settledValue; - continue; - } - else { - shouldDefer = true; - } - value = maybePromise; - } - } - ret[i] = value; - } + result[i] = maybePromise; } - return shouldDefer - ? Promise$_CreatePromiseArray(ret, PromiseArray, - Promise$_mapper, void 0).promise() - : ret; } + if (!isRejected) this.iterate(); +}; - function Promise$_Map(promises, fn, useBound, caller, ref) { - if (typeof fn !== "function") { - return apiRejection("fn must be a function"); - } +Mapping.prototype.isResolved = function Mapping$isResolved() { + return this.promise === null; +}; - if (useBound === true && promises._isBound()) { - fn = { - fn: fn, - receiver: promises._boundTo - }; - } +Mapping.prototype._promiseProgressed = +function Mapping$_promiseProgressed(value) { + if (this.isResolved()) return; + this.promise._progress(value); +}; - var ret = Promise$_CreatePromiseArray( - promises, - PromiseArray, - caller, - useBound === true && promises._isBound() - ? promises._boundTo - : void 0 - ).promise(); +Mapping.prototype._promiseFulfilled = +function Mapping$_promiseFulfilled(value, index) { + if (this.isResolved()) return; + this.result[index] = value; + if (this.shouldUnwrapItems) this.items[index] = value; + if (this.index === index) this.iterate(); +}; - if (ref !== void 0) { - ref.ref = ret; - } +Mapping.prototype._promiseRejected = +function Mapping$_promiseRejected(reason) { + this.reject(reason); +}; - return ret._then( - Promise$_mapper, - void 0, - void 0, - fn, - void 0, - caller - ); +Mapping.prototype.reject = function Mapping$reject(reason) { + if (this.isResolved()) return; + var trace = canAttach(reason) ? reason : new Error(reason + ""); + this.promise._attachExtraTrace(trace); + this.promise._reject(reason, trace); +}; + +Mapping.prototype.iterate = function Mapping$iterate() { + var i = this.index; + var items = this.items; + var result = this.result; + var len = items.length; + var result = this.result; + var receiver = this.receiver; + var callback = this.callback; + + for (; i < len; ++i) { + var value = result[i]; + if (value === pending) { + this.index = i; + return; + } + try { result[i] = callback.call(receiver, value, i, len); } + catch (e) { return this.reject(e); } } + this.promise._follow(all(result)); + this.items = this.result = this.callback = this.promise = null; +}; - Promise.prototype.map = function Promise$map(fn, ref) { - return Promise$_Map(this, fn, true, this.map, ref); - }; +Promise.prototype.map = function Promise$map(fn, ref) { + return Promise$_Map(this, fn, true, ref); +}; - Promise.map = function Promise$Map(promises, fn, ref) { - return Promise$_Map(promises, fn, false, Promise.map, ref); - }; +Promise.map = function Promise$Map(promises, fn, ref) { + return Promise$_Map(promises, fn, false, ref); +}; }; -},{}],17:[function(require,module,exports){ +},{"./errors.js":9,"./util.js":37}],17:[function(require,module,exports){ /** * Copyright (c) 2014 Petka Antonov * @@ -1466,48 +1479,47 @@ module.exports = function( */ "use strict"; module.exports = function(Promise) { - var util = require("./util.js"); - var async = require("./async.js"); - var tryCatch2 = util.tryCatch2; - var tryCatch1 = util.tryCatch1; - var errorObj = util.errorObj; +var util = require("./util.js"); +var async = require("./async.js"); +var tryCatch2 = util.tryCatch2; +var tryCatch1 = util.tryCatch1; +var errorObj = util.errorObj; - function thrower(r) { - throw r; - } +function thrower(r) { + throw r; +} - function Promise$_successAdapter(val, receiver) { - var nodeback = this; - var ret = tryCatch2(nodeback, receiver, null, val); - if (ret === errorObj) { - async.invokeLater(thrower, void 0, ret.e); - } +function Promise$_successAdapter(val, receiver) { + var nodeback = this; + var ret = tryCatch2(nodeback, receiver, null, val); + if (ret === errorObj) { + async.invokeLater(thrower, void 0, ret.e); } - function Promise$_errorAdapter(reason, receiver) { - var nodeback = this; - var ret = tryCatch1(nodeback, receiver, reason); - if (ret === errorObj) { - async.invokeLater(thrower, void 0, ret.e); - } +} +function Promise$_errorAdapter(reason, receiver) { + var nodeback = this; + var ret = tryCatch1(nodeback, receiver, reason); + if (ret === errorObj) { + async.invokeLater(thrower, void 0, ret.e); } +} - Promise.prototype.nodeify = function Promise$nodeify(nodeback) { - if (typeof nodeback == "function") { - this._then( - Promise$_successAdapter, - Promise$_errorAdapter, - void 0, - nodeback, - this._isBound() ? this._boundTo : null, - this.nodeify - ); - return; - } - return this; - }; +Promise.prototype.nodeify = function Promise$nodeify(nodeback) { + if (typeof nodeback == "function") { + this._then( + Promise$_successAdapter, + Promise$_errorAdapter, + void 0, + nodeback, + this._isBound() ? this._boundTo : null + ); + return; + } + return this; +}; }; -},{"./async.js":2,"./util.js":38}],18:[function(require,module,exports){ +},{"./async.js":2,"./util.js":37}],18:[function(require,module,exports){ /** * Copyright (c) 2014 Petka Antonov * @@ -1532,97 +1544,95 @@ module.exports = function(Promise) { */ "use strict"; module.exports = function(Promise, isPromiseArrayProxy) { - var util = require("./util.js"); - var async = require("./async.js"); - var errors = require("./errors.js"); - var tryCatch1 = util.tryCatch1; - var errorObj = util.errorObj; - - Promise.prototype.progressed = function Promise$progressed(handler) { - return this._then(void 0, void 0, handler, - void 0, void 0, this.progressed); - }; +var util = require("./util.js"); +var async = require("./async.js"); +var errors = require("./errors.js"); +var tryCatch1 = util.tryCatch1; +var errorObj = util.errorObj; - Promise.prototype._progress = function Promise$_progress(progressValue) { - if (this._isFollowingOrFulfilledOrRejected()) return; - this._progressUnchecked(progressValue); +Promise.prototype.progressed = function Promise$progressed(handler) { + return this._then(void 0, void 0, handler, void 0, void 0); +}; - }; +Promise.prototype._progress = function Promise$_progress(progressValue) { + if (this._isFollowingOrFulfilledOrRejected()) return; + this._progressUnchecked(progressValue); - Promise.prototype._progressHandlerAt = - function Promise$_progressHandlerAt(index) { - if (index === 0) return this._progressHandler0; - return this[index + 2 - 5]; - }; +}; - Promise.prototype._doProgressWith = - function Promise$_doProgressWith(progression) { - var progressValue = progression.value; - var handler = progression.handler; - var promise = progression.promise; - var receiver = progression.receiver; - - this._pushContext(); - var ret = tryCatch1(handler, receiver, progressValue); - this._popContext(); - - if (ret === errorObj) { - if (ret.e != null && - ret.e.name !== "StopProgressPropagation") { - var trace = errors.canAttach(ret.e) - ? ret.e : new Error(ret.e + ""); - promise._attachExtraTrace(trace); - promise._progress(ret.e); - } - } - else if (Promise.is(ret)) { - ret._then(promise._progress, null, null, promise, void 0, - this._progress); - } - else { - promise._progress(ret); - } - }; +Promise.prototype._progressHandlerAt = +function Promise$_progressHandlerAt(index) { + if (index === 0) return this._progressHandler0; + return this[index + 2 - 5]; +}; +Promise.prototype._doProgressWith = +function Promise$_doProgressWith(progression) { + var progressValue = progression.value; + var handler = progression.handler; + var promise = progression.promise; + var receiver = progression.receiver; - Promise.prototype._progressUnchecked = - function Promise$_progressUnchecked(progressValue) { - if (!this.isPending()) return; - var len = this._length(); + this._pushContext(); + var ret = tryCatch1(handler, receiver, progressValue); + this._popContext(); - for (var i = 0; i < len; i += 5) { - var handler = this._progressHandlerAt(i); - var promise = this._promiseAt(i); - if (!Promise.is(promise)) { - var receiver = this._receiverAt(i); - if (typeof handler === "function") { - handler.call(receiver, progressValue, promise); - } - else if (Promise.is(receiver) && receiver._isProxied()) { - receiver._progressUnchecked(progressValue); - } - else if (isPromiseArrayProxy(receiver, promise)) { - receiver._promiseProgressed(progressValue, promise); - } - continue; - } + if (ret === errorObj) { + if (ret.e != null && + ret.e.name !== "StopProgressPropagation") { + var trace = errors.canAttach(ret.e) + ? ret.e : new Error(ret.e + ""); + promise._attachExtraTrace(trace); + promise._progress(ret.e); + } + } + else if (ret instanceof Promise) { + ret._then(promise._progress, null, null, promise, void 0); + } + else { + promise._progress(ret); + } +}; + +Promise.prototype._progressUnchecked = +function Promise$_progressUnchecked(progressValue) { + if (!this.isPending()) return; + var len = this._length(); + var progress = this._progress; + for (var i = 0; i < len; i += 5) { + var handler = this._progressHandlerAt(i); + var promise = this._promiseAt(i); + if (!(promise instanceof Promise)) { + var receiver = this._receiverAt(i); if (typeof handler === "function") { - async.invoke(this._doProgressWith, this, { - handler: handler, - promise: promise, - receiver: this._receiverAt(i), - value: progressValue - }); + handler.call(receiver, progressValue, promise); } - else { - async.invoke(promise._progress, promise, progressValue); + else if (receiver instanceof Promise && receiver._isProxied()) { + receiver._progressUnchecked(progressValue); } + else if (isPromiseArrayProxy(receiver, promise)) { + receiver._promiseProgressed(progressValue, promise); + } + continue; } - }; + + if (typeof handler === "function") { + async.invoke(this._doProgressWith, this, { + handler: handler, + promise: promise, + receiver: this._receiverAt(i), + value: progressValue + }); + } + else { + async.invoke(progress, promise, progressValue); + } + } +}; }; -},{"./async.js":2,"./errors.js":9,"./util.js":38}],19:[function(require,module,exports){ +},{"./async.js":2,"./errors.js":9,"./util.js":37}],19:[function(require,module,exports){ /** * Copyright (c) 2014 Petka Antonov * @@ -1714,7 +1724,7 @@ function Promise(resolver) { Promise.prototype.bind = function Promise$bind(thisArg) { var ret = new Promise(INTERNAL); - if (debugging) ret._setTrace(this.bind, this); + ret._setTrace(this); ret._follow(this); ret._setBoundTo(thisArg); if (this._cancellable()) { @@ -1753,52 +1763,33 @@ function Promise$catch(fn) { catchInstances.length = j; fn = arguments[i]; - this._resetTrace(this.caught); + this._resetTrace(); var catchFilter = new CatchFilter(catchInstances, fn, this); return this._then(void 0, catchFilter.doFilter, void 0, - catchFilter, void 0, this.caught); + catchFilter, void 0); } - return this._then(void 0, fn, void 0, void 0, void 0, this.caught); + return this._then(void 0, fn, void 0, void 0, void 0); }; Promise.prototype.then = function Promise$then(didFulfill, didReject, didProgress) { return this._then(didFulfill, didReject, didProgress, - void 0, void 0, this.then); + void 0, void 0); }; Promise.prototype.done = function Promise$done(didFulfill, didReject, didProgress) { var promise = this._then(didFulfill, didReject, didProgress, - void 0, void 0, this.done); + void 0, void 0); promise._setIsFinal(); }; Promise.prototype.spread = function Promise$spread(didFulfill, didReject) { return this._then(didFulfill, didReject, void 0, - APPLY, void 0, this.spread); + APPLY, void 0); }; -Promise.prototype.isFulfilled = function Promise$isFulfilled() { - return (this._bitField & 268435456) > 0; -}; - - -Promise.prototype.isRejected = function Promise$isRejected() { - return (this._bitField & 134217728) > 0; -}; - -Promise.prototype.isPending = function Promise$isPending() { - return !this.isResolved(); -}; - - -Promise.prototype.isResolved = function Promise$isResolved() { - return (this._bitField & 402653184) > 0; -}; - - Promise.prototype.isCancellable = function Promise$isCancellable() { return !this.isResolved() && this._cancellable(); @@ -1823,38 +1814,34 @@ Promise.prototype.toJSON = function Promise$toJSON() { }; Promise.prototype.all = function Promise$all() { - return Promise$_all(this, true, this.all); + return Promise$_all(this, true); }; Promise.is = isPromise; -function Promise$_all(promises, useBound, caller) { +function Promise$_all(promises, useBound) { return Promise$_CreatePromiseArray( promises, PromiseArray, - caller, useBound === true && promises._isBound() ? promises._boundTo : void 0 ).promise(); } Promise.all = function Promise$All(promises) { - return Promise$_all(promises, false, Promise.all); + return Promise$_all(promises, false); }; Promise.join = function Promise$Join() { var $_len = arguments.length;var args = new Array($_len); for(var $_i = 0; $_i < $_len; ++$_i) {args[$_i] = arguments[$_i];} - return Promise$_CreatePromiseArray( - args, PromiseArray, Promise.join, void 0).promise(); + return Promise$_CreatePromiseArray(args, PromiseArray, void 0).promise(); }; Promise.resolve = Promise.fulfilled = -function Promise$Resolve(value, caller) { +function Promise$Resolve(value) { var ret = new Promise(INTERNAL); - if (debugging) ret._setTrace(typeof caller === "function" - ? caller - : Promise.resolve, void 0); + ret._setTrace(void 0); if (ret._tryFollow(value)) { return ret; } @@ -1866,7 +1853,7 @@ function Promise$Resolve(value, caller) { Promise.reject = Promise.rejected = function Promise$Reject(reason) { var ret = new Promise(INTERNAL); - if (debugging) ret._setTrace(Promise.reject, void 0); + ret._setTrace(void 0); markAsOriginatingFromRejection(reason); ret._cleanValues(); ret._setRejected(); @@ -1884,7 +1871,7 @@ Promise.prototype.error = function Promise$_error(fn) { }; Promise.prototype._resolveFromSyncValue = -function Promise$_resolveFromSyncValue(value, caller) { +function Promise$_resolveFromSyncValue(value) { if (value === errorObj) { this._cleanValues(); this._setRejected(); @@ -1892,7 +1879,7 @@ function Promise$_resolveFromSyncValue(value, caller) { this._ensurePossibleRejectionHandled(); } else { - var maybePromise = Promise._cast(value, caller, void 0); + var maybePromise = Promise._cast(value, void 0); if (maybePromise instanceof Promise) { this._follow(maybePromise); } @@ -1919,14 +1906,13 @@ Promise.method = function Promise$_Method(fn) { value = tryCatchApply(fn, args, this); break; } var ret = new Promise(INTERNAL); - if (debugging) ret._setTrace(Promise$_method, void 0); - ret._resolveFromSyncValue(value, Promise$_method); + ret._setTrace(void 0); + ret._resolveFromSyncValue(value); return ret; }; }; Promise.attempt = Promise["try"] = function Promise$_Try(fn, args, ctx) { - if (typeof fn !== "function") { return apiRejection("fn must be a function"); } @@ -1935,45 +1921,43 @@ Promise.attempt = Promise["try"] = function Promise$_Try(fn, args, ctx) { : tryCatch1(fn, ctx, args); var ret = new Promise(INTERNAL); - if (debugging) ret._setTrace(Promise.attempt, void 0); - ret._resolveFromSyncValue(value, Promise.attempt); + ret._setTrace(void 0); + ret._resolveFromSyncValue(value); return ret; }; -Promise.defer = Promise.pending = function Promise$Defer(caller) { +Promise.defer = Promise.pending = function Promise$Defer() { var promise = new Promise(INTERNAL); - if (debugging) promise._setTrace(typeof caller === "function" - ? caller : Promise.defer, void 0); + promise._setTrace(void 0); return new PromiseResolver(promise); }; Promise.bind = function Promise$Bind(thisArg) { var ret = new Promise(INTERNAL); - if (debugging) ret._setTrace(Promise.bind, void 0); + ret._setTrace(void 0); ret._setFulfilled(); ret._setBoundTo(thisArg); return ret; }; -Promise.cast = function Promise$_Cast(obj, caller) { - if (typeof caller !== "function") { - caller = Promise.cast; - } - var ret = Promise._cast(obj, caller, void 0); +Promise.cast = function Promise$_Cast(obj) { + var ret = Promise._cast(obj, void 0); if (!(ret instanceof Promise)) { - return Promise.resolve(ret, caller); + return Promise.resolve(ret); } return ret; }; Promise.onPossiblyUnhandledRejection = function Promise$OnPossiblyUnhandledRejection(fn) { - if (typeof fn === "function") { - CapturedTrace.possiblyUnhandledRejection = fn; - } - else { - CapturedTrace.possiblyUnhandledRejection = void 0; - } + CapturedTrace.possiblyUnhandledRejection = typeof fn === "function" + ? fn : void 0; +}; + +var unhandledRejectionHandled; +Promise.onUnhandledRejectionHandled = +function Promise$onUnhandledRejectionHandled(fn) { + unhandledRejectionHandled = typeof fn === "function" ? fn : void 0; }; var debugging = false || !!( @@ -2002,7 +1986,7 @@ Promise.prototype._setProxyHandlers = function Promise$_setProxyHandlers(receiver, promiseSlotValue) { var index = this._length(); - if (index >= 1048575 - 5) { + if (index >= 524287 - 5) { index = 0; this._setLength(0); } @@ -2037,8 +2021,7 @@ function Promise$_then( didReject, didProgress, receiver, - internalData, - caller + internalData ) { var haveInternalData = internalData !== void 0; var ret = haveInternalData ? internalData : new Promise(INTERNAL); @@ -2046,9 +2029,7 @@ function Promise$_then( if (debugging && !haveInternalData) { var haveSameContext = this._peekContext() === this._traceParent; ret._traceParent = haveSameContext ? this._traceParent : this; - ret._setTrace(typeof caller === "function" - ? caller - : this._then, this); + ret._setTrace(this); } if (!haveInternalData && this._isBound()) { @@ -2071,7 +2052,7 @@ function Promise$_then( }; Promise.prototype._length = function Promise$_length() { - return this._bitField & 1048575; + return this._bitField & 524287; }; Promise.prototype._isFollowingOrFulfilledOrRejected = @@ -2084,8 +2065,8 @@ Promise.prototype._isFollowing = function Promise$_isFollowing() { }; Promise.prototype._setLength = function Promise$_setLength(len) { - this._bitField = (this._bitField & -1048576) | - (len & 1048575); + this._bitField = (this._bitField & -524288) | + (len & 524287); }; Promise.prototype._setFulfilled = function Promise$_setFulfilled() { @@ -2128,6 +2109,10 @@ function Promise$_setRejectionIsUnhandled() { Promise.prototype._unsetRejectionIsUnhandled = function Promise$_unsetRejectionIsUnhandled() { this._bitField = this._bitField & (~2097152); + if (this._isUnhandledRejectionNotified()) { + this._unsetUnhandledRejectionIsNotified(); + this._notifyUnhandledRejectionIsHandled(); + } }; Promise.prototype._isRejectionUnhandled = @@ -2135,6 +2120,21 @@ function Promise$_isRejectionUnhandled() { return (this._bitField & 2097152) > 0; }; +Promise.prototype._setUnhandledRejectionIsNotified = +function Promise$_setUnhandledRejectionIsNotified() { + this._bitField = this._bitField | 524288; +}; + +Promise.prototype._unsetUnhandledRejectionIsNotified = +function Promise$_unsetUnhandledRejectionIsNotified() { + this._bitField = this._bitField & (~524288); +}; + +Promise.prototype._isUnhandledRejectionNotified = +function Promise$_isUnhandledRejectionNotified() { + return (this._bitField & 524288) > 0; +}; + Promise.prototype._setCarriedStackTrace = function Promise$_setCarriedStackTrace(capturedTrace) { this._bitField = this._bitField | 1048576; @@ -2212,11 +2212,9 @@ Promise.prototype._unsetAt = function Promise$_unsetAt(index) { Promise.prototype._resolveFromResolver = function Promise$_resolveFromResolver(resolver) { var promise = this; - var localDebugging = debugging; - if (localDebugging) { - this._setTrace(this._resolveFromResolver, void 0); - this._pushContext(); - } + this._setTrace(void 0); + this._pushContext(); + function Promise$_resolver(val) { if (promise._tryFollow(val)) { return; @@ -2230,7 +2228,7 @@ function Promise$_resolveFromResolver(resolver) { promise._reject(val, trace === val ? void 0 : trace); } var r = tryCatch2(resolver, void 0, Promise$_resolver, Promise$_rejecter); - if (localDebugging) this._popContext(); + this._popContext(); if (r !== void 0 && r === errorObj) { var e = r.e; @@ -2248,7 +2246,7 @@ Promise.prototype._addCallbacks = function Promise$_addCallbacks( ) { var index = this._length(); - if (index >= 1048575 - 5) { + if (index >= 524287 - 5) { index = 0; this._setLength(0); } @@ -2296,11 +2294,11 @@ Promise.prototype._spreadSlowCase = function Promise$_spreadSlowCase(targetFn, promise, values, boundTo) { var promiseForAll = Promise$_CreatePromiseArray - (values, PromiseArray, this._spreadSlowCase, boundTo) + (values, PromiseArray, boundTo) .promise() ._then(function() { return targetFn.apply(boundTo, arguments); - }, void 0, void 0, APPLY, void 0, this._spreadSlowCase); + }, void 0, void 0, APPLY, void 0); promise._follow(promiseForAll); }; @@ -2309,9 +2307,8 @@ Promise.prototype._callSpread = function Promise$_callSpread(handler, promise, value, localDebugging) { var boundTo = this._isBound() ? this._boundTo : void 0; if (isArray(value)) { - var caller = this._settlePromiseFromHandler; for (var i = 0, len = value.length; i < len; ++i) { - if (isPromise(Promise._cast(value[i], caller, void 0))) { + if (isPromise(Promise._cast(value[i], void 0))) { this._spreadSlowCase(handler, promise, value, boundTo); return; } @@ -2360,10 +2357,7 @@ function Promise$_settlePromiseFromHandler( promise._rejectUnchecked(err, trace); } else { - var castValue = Promise._cast(x, - localDebugging ? this._settlePromiseFromHandler : void 0, - promise); - + var castValue = Promise._cast(x, promise); if (isPromise(castValue)) { if (castValue.isRejected() && !castValue._isCarryingStackTrace() && @@ -2417,7 +2411,7 @@ function Promise$_tryFollow(value) { value === this) { return false; } - var maybePromise = Promise._cast(value, this._tryFollow, void 0); + var maybePromise = Promise._cast(value, void 0); if (!isPromise(maybePromise)) { return false; } @@ -2425,20 +2419,13 @@ function Promise$_tryFollow(value) { return true; }; -Promise.prototype._resetTrace = function Promise$_resetTrace(caller) { +Promise.prototype._resetTrace = function Promise$_resetTrace() { if (debugging) { - var context = this._peekContext(); - var isTopLevel = context === void 0; - this._trace = new CapturedTrace( - typeof caller === "function" - ? caller - : this._resetTrace, - isTopLevel - ); + this._trace = new CapturedTrace(this._peekContext() === void 0); } }; -Promise.prototype._setTrace = function Promise$_setTrace(caller, parent) { +Promise.prototype._setTrace = function Promise$_setTrace(parent) { if (debugging) { var context = this._peekContext(); this._traceParent = context; @@ -2448,12 +2435,7 @@ Promise.prototype._setTrace = function Promise$_setTrace(caller, parent) { this._trace = parent._trace; } else { - this._trace = new CapturedTrace( - typeof caller === "function" - ? caller - : this._setTrace, - isTopLevel - ); + this._trace = new CapturedTrace(isTopLevel); } } return this; @@ -2534,19 +2516,15 @@ Promise.prototype._settlePromiseAt = function Promise$_settlePromiseAt(index) { done = true; } else if (isPromiseArrayProxy(receiver, promise)) { - if (isFulfilled) receiver._promiseFulfilled(value, promise); else receiver._promiseRejected(value, promise); - done = true; } } if (!done) { - if (isFulfilled) promise._fulfill(value); else promise._reject(value, this._getCarriedStackTrace()); - } } @@ -2614,7 +2592,7 @@ function Promise$_fulfillUnchecked(value) { var len = this._length(); if (len > 0) { - async.invoke(this._fulfillPromises, this, len); + async.invoke(this._settlePromises, this, len); } }; @@ -2653,15 +2631,12 @@ function Promise$_rejectUnchecked(reason, trace) { }; Promise.prototype._rejectPromises = function Promise$_rejectPromises() { - var len = this._length(); - for (var i = 0; i < len; i+= 5) { - this._settlePromiseAt(i); - } + this._settlePromises(); this._unsetCarriedStackTrace(); }; -Promise.prototype._fulfillPromises = function Promise$_fulfillPromises(len) { - len = this._length(); +Promise.prototype._settlePromises = function Promise$_settlePromises() { + var len = this._length(); for (var i = 0; i < len; i+= 5) { this._settlePromiseAt(i); } @@ -2675,13 +2650,20 @@ function Promise$_ensurePossibleRejectionHandled() { } }; +Promise.prototype._notifyUnhandledRejectionIsHandled = +function Promise$_notifyUnhandledRejectionIsHandled() { + if (typeof unhandledRejectionHandled === "function") { + async.invokeLater(unhandledRejectionHandled, void 0, this); + } +}; + Promise.prototype._notifyUnhandledRejection = function Promise$_notifyUnhandledRejection() { if (this._isRejectionUnhandled()) { var reason = this._settledValue; var trace = this._getCarriedStackTrace(); - this._unsetRejectionIsUnhandled(); + this._setUnhandledRejectionIsNotified(); if (trace !== void 0) { this._unsetCarriedStackTrace(); @@ -2714,14 +2696,14 @@ Promise.prototype._popContext = function Promise$_popContext() { }; function Promise$_CreatePromiseArray( - promises, PromiseArrayConstructor, caller, boundTo) { + promises, PromiseArrayConstructor, boundTo) { var list = null; if (isArray(promises)) { list = promises; } else { - list = Promise._cast(promises, caller, void 0); + list = Promise._cast(promises, void 0); if (list !== promises) { list._setBoundTo(boundTo); } @@ -2730,13 +2712,7 @@ function Promise$_CreatePromiseArray( } } if (list !== null) { - return new PromiseArrayConstructor( - list, - typeof caller === "function" - ? caller - : Promise$_CreatePromiseArray, - boundTo - ); + return new PromiseArrayConstructor(list, boundTo); } return { promise: function() {return apiRejection("expecting an array, a promise or a thenable");} @@ -2744,7 +2720,6 @@ function Promise$_CreatePromiseArray( } var old = global.Promise; - Promise.noConflict = function() { if (global.Promise === Promise) { global.Promise = old; @@ -2761,6 +2736,7 @@ Promise._makeSelfResolutionError = makeSelfResolutionError; require("./finally.js")(Promise, NEXT_FILTER); require("./direct_resolve.js")(Promise); require("./thenables.js")(Promise, INTERNAL); +require("./synchronous_inspection.js")(Promise); Promise.RangeError = RangeError; Promise.CancellationError = CancellationError; Promise.TimeoutError = TimeoutError; @@ -2770,13 +2746,12 @@ Promise.RejectionError = RejectionError; util.toFastProperties(Promise); util.toFastProperties(Promise.prototype); require('./timers.js')(Promise,INTERNAL); -require('./synchronous_inspection.js')(Promise); require('./any.js')(Promise,Promise$_CreatePromiseArray,PromiseArray); require('./race.js')(Promise,INTERNAL); require('./call_get.js')(Promise); require('./filter.js')(Promise,Promise$_CreatePromiseArray,PromiseArray,apiRejection); require('./generators.js')(Promise,apiRejection,INTERNAL); -require('./map.js')(Promise,Promise$_CreatePromiseArray,PromiseArray,apiRejection); +require('./map.js')(Promise,PromiseArray,INTERNAL,apiRejection); require('./nodeify.js')(Promise); require('./promisify.js')(Promise,INTERNAL); require('./props.js')(Promise,PromiseArray); @@ -2791,7 +2766,7 @@ return Promise; }; -},{"./any.js":1,"./async.js":2,"./call_get.js":4,"./cancel.js":5,"./captured_trace.js":6,"./catch_filter.js":7,"./direct_resolve.js":8,"./errors.js":9,"./errors_api_rejection":10,"./filter.js":12,"./finally.js":13,"./generators.js":14,"./global.js":15,"./map.js":16,"./nodeify.js":17,"./progress.js":18,"./promise_array.js":20,"./promise_resolver.js":22,"./promisify.js":24,"./props.js":26,"./race.js":28,"./reduce.js":29,"./settle.js":31,"./some.js":33,"./synchronous_inspection.js":35,"./thenables.js":36,"./timers.js":37,"./util.js":38}],20:[function(require,module,exports){ +},{"./any.js":1,"./async.js":2,"./call_get.js":4,"./cancel.js":5,"./captured_trace.js":6,"./catch_filter.js":7,"./direct_resolve.js":8,"./errors.js":9,"./errors_api_rejection":10,"./filter.js":12,"./finally.js":13,"./generators.js":14,"./global.js":15,"./map.js":16,"./nodeify.js":17,"./progress.js":18,"./promise_array.js":20,"./promise_resolver.js":21,"./promisify.js":23,"./props.js":25,"./race.js":27,"./reduce.js":28,"./settle.js":30,"./some.js":32,"./synchronous_inspection.js":34,"./thenables.js":35,"./timers.js":36,"./util.js":37}],20:[function(require,module,exports){ /** * Copyright (c) 2014 Petka Antonov * @@ -2830,10 +2805,10 @@ function toResolutionValue(val) { } } -function PromiseArray(values, caller, boundTo) { +function PromiseArray(values, boundTo) { var promise = this._promise = new Promise(INTERNAL); var parent = void 0; - if (Promise.is(values)) { + if (values instanceof Promise) { parent = values; if (values._cancellable()) { promise._setCancellable(); @@ -2843,7 +2818,7 @@ function PromiseArray(values, caller, boundTo) { promise._setBoundTo(boundTo); } } - promise._setTrace(caller, parent); + promise._setTrace(parent); this._values = values; this._length = 0; this._totalResolved = 0; @@ -2862,7 +2837,7 @@ PromiseArray.prototype.promise = function PromiseArray$promise() { PromiseArray.prototype._init = function PromiseArray$_init(_, resolveValueIfEmpty) { var values = this._values; - if (Promise.is(values)) { + if (values instanceof Promise) { if (values.isFulfilled()) { values = values._settledValue; if (!isArray(values)) { @@ -2878,8 +2853,7 @@ function PromiseArray$_init(_, resolveValueIfEmpty) { this._reject, void 0, this, - resolveValueIfEmpty, - this.constructor + resolveValueIfEmpty ); return; } @@ -2909,7 +2883,7 @@ function PromiseArray$_init(_, resolveValueIfEmpty) { newLen--; continue; } - var maybePromise = Promise._cast(promise, void 0, void 0); + var maybePromise = Promise._cast(promise, void 0); if (maybePromise instanceof Promise) { if (maybePromise.isPending()) { maybePromise._proxyPromiseArray(this, i); @@ -2946,7 +2920,7 @@ function PromiseArray$_init(_, resolveValueIfEmpty) { PromiseArray.prototype._settlePromiseAt = function PromiseArray$_settlePromiseAt(index) { var value = this._values[index]; - if (!Promise.is(value)) { + if (!(value instanceof Promise)) { this._promiseFulfilled(value, index); } else if (value.isFulfilled()) { @@ -3026,75 +3000,7 @@ function PromiseArray$_promiseRejected(reason, index) { return PromiseArray; }; -},{"./async.js":2,"./errors.js":9,"./util.js":38}],21:[function(require,module,exports){ -/** - * Copyright (c) 2014 Petka Antonov - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions:

- * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - */ -"use strict"; -var TypeError = require("./errors.js").TypeError; - -function PromiseInspection(promise) { - if (promise !== void 0) { - this._bitField = promise._bitField; - this._settledValue = promise.isResolved() - ? promise._settledValue - : void 0; - } - else { - this._bitField = 0; - this._settledValue = void 0; - } -} -PromiseInspection.prototype.isFulfilled = -function PromiseInspection$isFulfilled() { - return (this._bitField & 268435456) > 0; -}; - -PromiseInspection.prototype.isRejected = -function PromiseInspection$isRejected() { - return (this._bitField & 134217728) > 0; -}; - -PromiseInspection.prototype.isPending = function PromiseInspection$isPending() { - return (this._bitField & 402653184) === 0; -}; - -PromiseInspection.prototype.value = function PromiseInspection$value() { - if (!this.isFulfilled()) { - throw new TypeError("cannot get fulfillment value of a non-fulfilled promise"); - } - return this._settledValue; -}; - -PromiseInspection.prototype.error = function PromiseInspection$error() { - if (!this.isRejected()) { - throw new TypeError("cannot get rejection reason of a non-rejected promise"); - } - return this._settledValue; -}; - -module.exports = PromiseInspection; - -},{"./errors.js":9}],22:[function(require,module,exports){ +},{"./async.js":2,"./errors.js":9,"./util.js":37}],21:[function(require,module,exports){ /** * Copyright (c) 2014 Petka Antonov * @@ -3248,7 +3154,7 @@ function PromiseResolver$_setCarriedStackTrace(trace) { module.exports = PromiseResolver; -},{"./async.js":2,"./errors.js":9,"./es5.js":11,"./util.js":38}],23:[function(require,module,exports){ +},{"./async.js":2,"./errors.js":9,"./es5.js":11,"./util.js":37}],22:[function(require,module,exports){ /** * Copyright (c) 2014 Petka Antonov * @@ -3298,9 +3204,9 @@ function promiseFromYieldHandler(value) { return null; } -function PromiseSpawn(generatorFunction, receiver, caller) { +function PromiseSpawn(generatorFunction, receiver) { var promise = this._promise = new Promise(INTERNAL); - promise._setTrace(caller, void 0); + promise._setTrace(void 0); this._generatorFunction = generatorFunction; this._receiver = receiver; this._generator = void 0; @@ -3353,8 +3259,7 @@ PromiseSpawn.prototype._continue = function PromiseSpawn$_continue(result) { this._throw, void 0, this, - null, - void 0 + null ); } }; @@ -3381,7 +3286,7 @@ PromiseSpawn.addYieldHandler = function PromiseSpawn$AddYieldHandler(fn) { return PromiseSpawn; }; -},{"./errors.js":9,"./util.js":38}],24:[function(require,module,exports){ +},{"./errors.js":9,"./util.js":37}],23:[function(require,module,exports){ /** * Copyright (c) 2014 Petka Antonov * @@ -3567,7 +3472,7 @@ function makeNodePromisifiedEval(callback, receiver, originalName, fn) { "(" + parameterDeclaration(newParameterCount) + ") {\"use strict\";" + "var len = arguments.length;" + "var promise = new Promise(INTERNAL);"+ - "promise._setTrace(" + callbackName + ", void 0);" + + "promise._setTrace(void 0);" + "var fn = nodebackForPromise(promise);"+ "try {" + "switch(len) {" + @@ -3594,7 +3499,7 @@ function makeNodePromisifiedClosure(callback, receiver) { callback = _receiver[callback]; } var promise = new Promise(INTERNAL); - promise._setTrace(promisified, void 0); + promise._setTrace(void 0); var fn = nodebackForPromise(promise); try { callback.apply(_receiver, withAppended(arguments, fn)); @@ -3661,7 +3566,7 @@ Promise.promisifyAll = function Promise$PromisifyAll(target) { }; -},{"./es5.js":11,"./promise_resolver.js":22,"./util.js":38}],25:[function(require,module,exports){ +},{"./es5.js":11,"./promise_resolver.js":21,"./util.js":37}],24:[function(require,module,exports){ /** * Copyright (c) 2014 Petka Antonov * @@ -3690,13 +3595,13 @@ var util = require("./util.js"); var inherits = util.inherits; var es5 = require("./es5.js"); -function PropertiesPromiseArray(obj, caller, boundTo) { +function PropertiesPromiseArray(obj, boundTo) { var keys = es5.keys(obj); var values = new Array(keys.length); for (var i = 0, len = values.length; i < len; ++i) { values[i] = obj[keys[i]]; } - this.constructor$(values, caller, boundTo); + this.constructor$(values, boundTo); if (!this._isResolved()) { for (var i = 0, len = keys.length; i < len; ++i) { values.push(keys[i]); @@ -3740,7 +3645,7 @@ PromiseArray.PropertiesPromiseArray = PropertiesPromiseArray; return PropertiesPromiseArray; }; -},{"./es5.js":11,"./util.js":38}],26:[function(require,module,exports){ +},{"./es5.js":11,"./util.js":37}],25:[function(require,module,exports){ /** * Copyright (c) 2014 Petka Antonov * @@ -3765,49 +3670,48 @@ return PropertiesPromiseArray; */ "use strict"; module.exports = function(Promise, PromiseArray) { - var PropertiesPromiseArray = require("./properties_promise_array.js")( - Promise, PromiseArray); - var util = require("./util.js"); - var apiRejection = require("./errors_api_rejection")(Promise); - var isObject = util.isObject; - - function Promise$_Props(promises, useBound, caller) { - var ret; - var castValue = Promise._cast(promises, caller, void 0); - - if (!isObject(castValue)) { - return apiRejection("cannot await properties of a non-object"); - } - else if (Promise.is(castValue)) { - ret = castValue._then(Promise.props, void 0, void 0, - void 0, void 0, caller); - } - else { - ret = new PropertiesPromiseArray( - castValue, - caller, - useBound === true && castValue._isBound() - ? castValue._boundTo - : void 0 - ).promise(); - useBound = false; - } - if (useBound === true && castValue._isBound()) { - ret._setBoundTo(castValue._boundTo); - } - return ret; +var PropertiesPromiseArray = require("./properties_promise_array.js")( + Promise, PromiseArray); +var util = require("./util.js"); +var apiRejection = require("./errors_api_rejection")(Promise); +var isObject = util.isObject; + +function Promise$_Props(promises, useBound) { + var ret; + var castValue = Promise._cast(promises, void 0); + + if (!isObject(castValue)) { + return apiRejection("cannot await properties of a non-object"); } + else if (castValue instanceof Promise) { + ret = castValue._then(Promise.props, void 0, void 0, + void 0, void 0); + } + else { + ret = new PropertiesPromiseArray( + castValue, + useBound === true && castValue._isBound() + ? castValue._boundTo + : void 0 + ).promise(); + useBound = false; + } + if (useBound === true && castValue._isBound()) { + ret._setBoundTo(castValue._boundTo); + } + return ret; +} - Promise.prototype.props = function Promise$props() { - return Promise$_Props(this, true, this.props); - }; +Promise.prototype.props = function Promise$props() { + return Promise$_Props(this, true); +}; - Promise.props = function Promise$Props(promises) { - return Promise$_Props(promises, false, Promise.props); - }; +Promise.props = function Promise$Props(promises) { + return Promise$_Props(promises, false); +}; }; -},{"./errors_api_rejection":10,"./properties_promise_array.js":25,"./util.js":38}],27:[function(require,module,exports){ +},{"./errors_api_rejection":10,"./properties_promise_array.js":24,"./util.js":37}],26:[function(require,module,exports){ /** * Copyright (c) 2014 Petka Antonov * @@ -3944,7 +3848,7 @@ Queue.prototype._resizeTo = function Queue$_resizeTo(capacity) { module.exports = Queue; -},{}],28:[function(require,module,exports){ +},{}],27:[function(require,module,exports){ /** * Copyright (c) 2014 Petka Antonov * @@ -3969,69 +3873,68 @@ module.exports = Queue; */ "use strict"; module.exports = function(Promise, INTERNAL) { - var apiRejection = require("./errors_api_rejection.js")(Promise); - var isArray = require("./util.js").isArray; +var apiRejection = require("./errors_api_rejection.js")(Promise); +var isArray = require("./util.js").isArray; - var raceLater = function Promise$_raceLater(promise) { - return promise.then(function Promise$_lateRacer(array) { - return Promise$_Race(array, Promise$_lateRacer, promise); - }); - }; +var raceLater = function Promise$_raceLater(promise) { + return promise.then(function(array) { + return Promise$_Race(array, promise); + }); +}; + +var hasOwn = {}.hasOwnProperty; +function Promise$_Race(promises, parent) { + var maybePromise = Promise._cast(promises, void 0); - var hasOwn = {}.hasOwnProperty; - function Promise$_Race(promises, caller, parent) { - var maybePromise = Promise._cast(promises, caller, void 0); + if (maybePromise instanceof Promise) { + return raceLater(maybePromise); + } + else if (!isArray(promises)) { + return apiRejection("expecting an array, a promise or a thenable"); + } - if (Promise.is(maybePromise)) { - return raceLater(maybePromise); + var ret = new Promise(INTERNAL); + ret._setTrace(parent); + if (parent !== void 0) { + if (parent._isBound()) { + ret._setBoundTo(parent._boundTo); } - else if (!isArray(promises)) { - return apiRejection("expecting an array, a promise or a thenable"); + if (parent._cancellable()) { + ret._setCancellable(); + ret._cancellationParent = parent; } + } + var fulfill = ret._fulfill; + var reject = ret._reject; + for (var i = 0, len = promises.length; i < len; ++i) { + var val = promises[i]; - var ret = new Promise(INTERNAL); - ret._setTrace(caller, parent); - if (parent !== void 0) { - if (parent._isBound()) { - ret._setBoundTo(parent._boundTo); - } - if (parent._cancellable()) { - ret._setCancellable(); - ret._cancellationParent = parent; - } + if (val === void 0 && !(hasOwn.call(promises, i))) { + continue; } - var fulfill = ret._fulfill; - var reject = ret._reject; - for (var i = 0, len = promises.length; i < len; ++i) { - var val = promises[i]; - if (val === void 0 && !(hasOwn.call(promises, i))) { - continue; - } - - Promise.cast(val)._then( - fulfill, - reject, - void 0, - ret, - null, - caller - ); - } - return ret; + Promise.cast(val)._then( + fulfill, + reject, + void 0, + ret, + null + ); } + return ret; +} - Promise.race = function Promise$Race(promises) { - return Promise$_Race(promises, Promise.race, void 0); - }; +Promise.race = function Promise$Race(promises) { + return Promise$_Race(promises, void 0); +}; - Promise.prototype.race = function Promise$race() { - return Promise$_Race(this, this.race, void 0); - }; +Promise.prototype.race = function Promise$race() { + return Promise$_Race(this, void 0); +}; }; -},{"./errors_api_rejection.js":10,"./util.js":38}],29:[function(require,module,exports){ +},{"./errors_api_rejection.js":10,"./util.js":37}],28:[function(require,module,exports){ /** * Copyright (c) 2014 Petka Antonov * @@ -4059,154 +3962,142 @@ module.exports = function( Promise, Promise$_CreatePromiseArray, PromiseArray, apiRejection, INTERNAL) { - function Reduction(callback, index, accum, items, receiver) { - this.promise = new Promise(INTERNAL); - this.index = index; - this.length = items.length; - this.items = items; - this.callback = callback; - this.receiver = receiver; - this.accum = accum; - } +function Reduction(callback, index, accum, items, receiver) { + this.promise = new Promise(INTERNAL); + this.index = index; + this.length = items.length; + this.items = items; + this.callback = callback; + this.receiver = receiver; + this.accum = accum; +} - Reduction.prototype.reject = function Reduction$reject(e) { - this.promise._reject(e); - }; +Reduction.prototype.reject = function Reduction$reject(e) { + this.promise._reject(e); +}; - Reduction.prototype.fulfill = function Reduction$fulfill(value, index) { - this.accum = value; - this.index = index + 1; - this.iterate(); - }; +Reduction.prototype.fulfill = function Reduction$fulfill(value, index) { + this.accum = value; + this.index = index + 1; + this.iterate(); +}; - Reduction.prototype.iterate = function Reduction$iterate() { - var i = this.index; - var len = this.length; - var items = this.items; - var result = this.accum; - var receiver = this.receiver; - var callback = this.callback; - var iterate = this.iterate; - - for(; i < len; ++i) { - result = Promise._cast( - callback.call( - receiver, - result, - items[i], - i, - len - ), - iterate, - void 0 - ); +Reduction.prototype.iterate = function Reduction$iterate() { + var i = this.index; + var len = this.length; + var items = this.items; + var result = this.accum; + var receiver = this.receiver; + var callback = this.callback; - if (result instanceof Promise) { - result._then( - this.fulfill, this.reject, void 0, this, i, iterate); - return; - } - } - this.promise._fulfill(result); - }; + for (; i < len; ++i) { + result = callback.call(receiver, result, items[i], i, len); + result = Promise._cast(result, void 0); - function Promise$_reducer(fulfilleds, initialValue) { - var fn = this; - var receiver = void 0; - if (typeof fn !== "function") { - receiver = fn.receiver; - fn = fn.fn; + if (result instanceof Promise) { + result._then( + this.fulfill, this.reject, void 0, this, i); + return; } - var len = fulfilleds.length; - var accum = void 0; - var startIndex = 0; + } + this.promise._fulfill(result); +}; - if (initialValue !== void 0) { - accum = initialValue; - startIndex = 0; - } - else { - startIndex = 1; - if (len > 0) accum = fulfilleds[0]; - } - var i = startIndex; +function Promise$_reducer(fulfilleds, initialValue) { + var fn = this; + var receiver = void 0; + if (typeof fn !== "function") { + receiver = fn.receiver; + fn = fn.fn; + } + var len = fulfilleds.length; + var accum = void 0; + var startIndex = 0; - if (i >= len) { - return accum; - } + if (initialValue !== void 0) { + accum = initialValue; + startIndex = 0; + } + else { + startIndex = 1; + if (len > 0) accum = fulfilleds[0]; + } + var i = startIndex; - var reduction = new Reduction(fn, i, accum, fulfilleds, receiver); - reduction.iterate(); - return reduction.promise; + if (i >= len) { + return accum; } - function Promise$_unpackReducer(fulfilleds) { - var fn = this.fn; - var initialValue = this.initialValue; - return Promise$_reducer.call(fn, fulfilleds, initialValue); + var reduction = new Reduction(fn, i, accum, fulfilleds, receiver); + reduction.iterate(); + return reduction.promise; +} + +function Promise$_unpackReducer(fulfilleds) { + var fn = this.fn; + var initialValue = this.initialValue; + return Promise$_reducer.call(fn, fulfilleds, initialValue); +} + +function Promise$_slowReduce( + promises, fn, initialValue, useBound) { + return initialValue._then(function(initialValue) { + return Promise$_Reduce( + promises, fn, initialValue, useBound); + }, void 0, void 0, void 0, void 0); +} + +function Promise$_Reduce(promises, fn, initialValue, useBound) { + if (typeof fn !== "function") { + return apiRejection("fn must be a function"); } - function Promise$_slowReduce( - promises, fn, initialValue, useBound, caller) { - return initialValue._then(function callee(initialValue) { - return Promise$_Reduce( - promises, fn, initialValue, useBound, callee); - }, void 0, void 0, void 0, void 0, caller); + if (useBound === true && promises._isBound()) { + fn = { + fn: fn, + receiver: promises._boundTo + }; } - function Promise$_Reduce(promises, fn, initialValue, useBound, caller) { - if (typeof fn !== "function") { - return apiRejection("fn must be a function"); + if (initialValue !== void 0) { + if (initialValue instanceof Promise) { + if (initialValue.isFulfilled()) { + initialValue = initialValue._settledValue; + } + else { + return Promise$_slowReduce(promises, + fn, initialValue, useBound); + } } - if (useBound === true && promises._isBound()) { - fn = { + return Promise$_CreatePromiseArray(promises, PromiseArray, + useBound === true && promises._isBound() + ? promises._boundTo + : void 0) + .promise() + ._then(Promise$_unpackReducer, void 0, void 0, { fn: fn, - receiver: promises._boundTo - }; - } - - if (initialValue !== void 0) { - if (Promise.is(initialValue)) { - if (initialValue.isFulfilled()) { - initialValue = initialValue._settledValue; - } - else { - return Promise$_slowReduce(promises, - fn, initialValue, useBound, caller); - } - } - - return Promise$_CreatePromiseArray(promises, PromiseArray, caller, - useBound === true && promises._isBound() - ? promises._boundTo - : void 0) - .promise() - ._then(Promise$_unpackReducer, void 0, void 0, { - fn: fn, - initialValue: initialValue - }, void 0, Promise.reduce); - } - return Promise$_CreatePromiseArray(promises, PromiseArray, caller, - useBound === true && promises._isBound() - ? promises._boundTo - : void 0).promise() - ._then(Promise$_reducer, void 0, void 0, fn, void 0, caller); + initialValue: initialValue + }, void 0); } + return Promise$_CreatePromiseArray(promises, PromiseArray, + useBound === true && promises._isBound() + ? promises._boundTo + : void 0).promise() + ._then(Promise$_reducer, void 0, void 0, fn, void 0); +} - Promise.reduce = function Promise$Reduce(promises, fn, initialValue) { - return Promise$_Reduce(promises, fn, - initialValue, false, Promise.reduce); - }; +Promise.reduce = function Promise$Reduce(promises, fn, initialValue) { + return Promise$_Reduce(promises, fn, initialValue, false); +}; - Promise.prototype.reduce = function Promise$reduce(fn, initialValue) { - return Promise$_Reduce(this, fn, initialValue, - true, this.reduce); - }; +Promise.prototype.reduce = function Promise$reduce(fn, initialValue) { + return Promise$_Reduce(this, fn, initialValue, true); +}; }; -},{}],30:[function(require,module,exports){ +},{}],29:[function(require,module,exports){ /** * Copyright (c) 2014 Petka Antonov * @@ -4329,7 +4220,7 @@ else { module.exports = schedule; -},{"./global.js":15}],31:[function(require,module,exports){ +},{"./global.js":15}],30:[function(require,module,exports){ /** * Copyright (c) 2014 Petka Antonov * @@ -4356,31 +4247,29 @@ module.exports = schedule; module.exports = function(Promise, Promise$_CreatePromiseArray, PromiseArray) { - var SettledPromiseArray = require("./settled_promise_array.js")( - Promise, PromiseArray); +var SettledPromiseArray = require("./settled_promise_array.js")( + Promise, PromiseArray); - function Promise$_Settle(promises, useBound, caller) { - return Promise$_CreatePromiseArray( - promises, - SettledPromiseArray, - caller, - useBound === true && promises._isBound() - ? promises._boundTo - : void 0 - ).promise(); - } - - Promise.settle = function Promise$Settle(promises) { - return Promise$_Settle(promises, false, Promise.settle); - }; +function Promise$_Settle(promises, useBound) { + return Promise$_CreatePromiseArray( + promises, + SettledPromiseArray, + useBound === true && promises._isBound() + ? promises._boundTo + : void 0 + ).promise(); +} - Promise.prototype.settle = function Promise$settle() { - return Promise$_Settle(this, true, this.settle); - }; +Promise.settle = function Promise$Settle(promises) { + return Promise$_Settle(promises, false); +}; +Promise.prototype.settle = function Promise$settle() { + return Promise$_Settle(this, true); +}; }; -},{"./settled_promise_array.js":32}],32:[function(require,module,exports){ +},{"./settled_promise_array.js":31}],31:[function(require,module,exports){ /** * Copyright (c) 2014 Petka Antonov * @@ -4405,11 +4294,11 @@ module.exports = */ "use strict"; module.exports = function(Promise, PromiseArray) { -var PromiseInspection = require("./promise_inspection.js"); +var PromiseInspection = Promise.PromiseInspection; var util = require("./util.js"); var inherits = util.inherits; -function SettledPromiseArray(values, caller, boundTo) { - this.constructor$(values, caller, boundTo); +function SettledPromiseArray(values, boundTo) { + this.constructor$(values, boundTo); } inherits(SettledPromiseArray, PromiseArray); @@ -4442,7 +4331,7 @@ function SettledPromiseArray$_promiseRejected(reason, index) { return SettledPromiseArray; }; -},{"./promise_inspection.js":21,"./util.js":38}],33:[function(require,module,exports){ +},{"./util.js":37}],32:[function(require,module,exports){ /** * Copyright (c) 2014 Petka Antonov * @@ -4469,39 +4358,38 @@ return SettledPromiseArray; module.exports = function(Promise, Promise$_CreatePromiseArray, PromiseArray, apiRejection) { - var SomePromiseArray = require("./some_promise_array.js")(PromiseArray); - function Promise$_Some(promises, howMany, useBound, caller) { - if ((howMany | 0) !== howMany || howMany < 0) { - return apiRejection("expecting a positive integer"); - } - var ret = Promise$_CreatePromiseArray( - promises, - SomePromiseArray, - caller, - useBound === true && promises._isBound() - ? promises._boundTo - : void 0 - ); - var promise = ret.promise(); - if (promise.isRejected()) { - return promise; - } - ret.setHowMany(howMany); - ret.init(); +var SomePromiseArray = require("./some_promise_array.js")(PromiseArray); +function Promise$_Some(promises, howMany, useBound) { + if ((howMany | 0) !== howMany || howMany < 0) { + return apiRejection("expecting a positive integer"); + } + var ret = Promise$_CreatePromiseArray( + promises, + SomePromiseArray, + useBound === true && promises._isBound() + ? promises._boundTo + : void 0 + ); + var promise = ret.promise(); + if (promise.isRejected()) { return promise; } + ret.setHowMany(howMany); + ret.init(); + return promise; +} - Promise.some = function Promise$Some(promises, howMany) { - return Promise$_Some(promises, howMany, false, Promise.some); - }; +Promise.some = function Promise$Some(promises, howMany) { + return Promise$_Some(promises, howMany, false); +}; - Promise.prototype.some = function Promise$some(count) { - return Promise$_Some(this, count, true, this.some); - }; +Promise.prototype.some = function Promise$some(count) { + return Promise$_Some(this, count, true); +}; }; -},{"./some_promise_array.js":34}],34:[function(require,module,exports){ +},{"./some_promise_array.js":33}],33:[function(require,module,exports){ /** * Copyright (c) 2014 Petka Antonov * @@ -4531,8 +4419,8 @@ var RangeError = require("./errors.js").RangeError; var inherits = util.inherits; var isArray = util.isArray; -function SomePromiseArray(values, caller, boundTo) { - this.constructor$(values, caller, boundTo); +function SomePromiseArray(values, boundTo) { + this.constructor$(values, boundTo); this._howMany = 0; this._unwrap = false; this._initialized = false; @@ -4634,7 +4522,7 @@ function SomePromiseArray$_canPossiblyFulfill() { return SomePromiseArray; }; -},{"./errors.js":9,"./util.js":38}],35:[function(require,module,exports){ +},{"./errors.js":9,"./util.js":37}],34:[function(require,module,exports){ /** * Copyright (c) 2014 Petka Antonov * @@ -4659,14 +4547,63 @@ return SomePromiseArray; */ "use strict"; module.exports = function(Promise) { - var PromiseInspection = require("./promise_inspection.js"); +function PromiseInspection(promise) { + if (promise !== void 0) { + this._bitField = promise._bitField; + this._settledValue = promise.isResolved() + ? promise._settledValue + : void 0; + } + else { + this._bitField = 0; + this._settledValue = void 0; + } +} - Promise.prototype.inspect = function Promise$inspect() { - return new PromiseInspection(this); - }; +PromiseInspection.prototype.isFulfilled = +Promise.prototype.isFulfilled = function Promise$isFulfilled() { + return (this._bitField & 268435456) > 0; +}; + +PromiseInspection.prototype.isRejected = +Promise.prototype.isRejected = function Promise$isRejected() { + return (this._bitField & 134217728) > 0; +}; + +PromiseInspection.prototype.isPending = +Promise.prototype.isPending = function Promise$isPending() { + return (this._bitField & 402653184) === 0; +}; + +PromiseInspection.prototype.value = +Promise.prototype.value = function Promise$value() { + if (!this.isFulfilled()) { + throw new TypeError("cannot get fulfillment value of a non-fulfilled promise"); + } + return this._settledValue; }; -},{"./promise_inspection.js":21}],36:[function(require,module,exports){ +PromiseInspection.prototype.error = +Promise.prototype.reason = function Promise$reason() { + if (!this.isRejected()) { + throw new TypeError("cannot get rejection reason of a non-rejected promise"); + } + return this._settledValue; +}; + +PromiseInspection.prototype.isResolved = +Promise.prototype.isResolved = function Promise$isResolved() { + return (this._bitField & 402653184) > 0; +}; + +Promise.prototype.inspect = function Promise$inspect() { + return new PromiseInspection(this); +}; + +Promise.PromiseInspection = PromiseInspection; +}; + +},{}],35:[function(require,module,exports){ /** * Copyright (c) 2014 Petka Antonov * @@ -4691,122 +4628,119 @@ module.exports = function(Promise) { */ "use strict"; module.exports = function(Promise, INTERNAL) { - var util = require("./util.js"); - var canAttach = require("./errors.js").canAttach; - var errorObj = util.errorObj; - var isObject = util.isObject; - - function getThen(obj) { - try { - return obj.then; - } - catch(e) { - errorObj.e = e; - return errorObj; - } - } +var util = require("./util.js"); +var canAttach = require("./errors.js").canAttach; +var errorObj = util.errorObj; +var isObject = util.isObject; - function Promise$_Cast(obj, caller, originalPromise) { - if (isObject(obj)) { - if (obj instanceof Promise) { - return obj; - } - else if (isAnyBluebirdPromise(obj)) { - var ret = new Promise(INTERNAL); - ret._setTrace(caller, void 0); - obj._then( - ret._fulfillUnchecked, - ret._rejectUncheckedCheckError, - ret._progressUnchecked, - ret, - null, - void 0 - ); - ret._setFollowing(); - return ret; - } - var then = getThen(obj); - if (then === errorObj) { - caller = typeof caller === "function" ? caller : Promise$_Cast; - if (originalPromise !== void 0 && canAttach(then.e)) { - originalPromise._attachExtraTrace(then.e); - } - return Promise.reject(then.e, caller); - } - else if (typeof then === "function") { - caller = typeof caller === "function" ? caller : Promise$_Cast; - return Promise$_doThenable(obj, then, caller, originalPromise); - } - } - return obj; +function getThen(obj) { + try { + return obj.then; } - - var hasProp = {}.hasOwnProperty; - function isAnyBluebirdPromise(obj) { - return hasProp.call(obj, "_promise0"); + catch(e) { + errorObj.e = e; + return errorObj; } +} - function Promise$_doThenable(x, then, caller, originalPromise) { - var resolver = Promise.defer(caller); - var called = false; - try { - then.call( - x, - Promise$_resolveFromThenable, - Promise$_rejectFromThenable, - Promise$_progressFromThenable +function Promise$_Cast(obj, originalPromise) { + if (isObject(obj)) { + if (obj instanceof Promise) { + return obj; + } + else if (isAnyBluebirdPromise(obj)) { + var ret = new Promise(INTERNAL); + ret._setTrace(void 0); + obj._then( + ret._fulfillUnchecked, + ret._rejectUncheckedCheckError, + ret._progressUnchecked, + ret, + null ); + ret._setFollowing(); + return ret; } - catch(e) { - if (!called) { - called = true; - var trace = canAttach(e) ? e : new Error(e + ""); - if (originalPromise !== void 0) { - originalPromise._attachExtraTrace(trace); - } - resolver.promise._reject(e, trace); + var then = getThen(obj); + if (then === errorObj) { + if (originalPromise !== void 0 && canAttach(then.e)) { + originalPromise._attachExtraTrace(then.e); } + return Promise.reject(then.e); } - return resolver.promise; - - function Promise$_resolveFromThenable(y) { - if (called) return; - called = true; - - if (x === y) { - var e = Promise._makeSelfResolutionError(); - if (originalPromise !== void 0) { - originalPromise._attachExtraTrace(e); - } - resolver.promise._reject(e, void 0); - return; - } - resolver.resolve(y); + else if (typeof then === "function") { + return Promise$_doThenable(obj, then, originalPromise); } + } + return obj; +} + +var hasProp = {}.hasOwnProperty; +function isAnyBluebirdPromise(obj) { + return hasProp.call(obj, "_promise0"); +} - function Promise$_rejectFromThenable(r) { - if (called) return; +function Promise$_doThenable(x, then, originalPromise) { + var resolver = Promise.defer(); + var called = false; + try { + then.call( + x, + Promise$_resolveFromThenable, + Promise$_rejectFromThenable, + Promise$_progressFromThenable + ); + } + catch(e) { + if (!called) { called = true; - var trace = canAttach(r) ? r : new Error(r + ""); + var trace = canAttach(e) ? e : new Error(e + ""); if (originalPromise !== void 0) { originalPromise._attachExtraTrace(trace); } - resolver.promise._reject(r, trace); + resolver.promise._reject(e, trace); } + } + return resolver.promise; + + function Promise$_resolveFromThenable(y) { + if (called) return; + called = true; - function Promise$_progressFromThenable(v) { - if (called) return; - var promise = resolver.promise; - if (typeof promise._progress === "function") { - promise._progress(v); + if (x === y) { + var e = Promise._makeSelfResolutionError(); + if (originalPromise !== void 0) { + originalPromise._attachExtraTrace(e); } + resolver.promise._reject(e, void 0); + return; + } + resolver.resolve(y); + } + + function Promise$_rejectFromThenable(r) { + if (called) return; + called = true; + var trace = canAttach(r) ? r : new Error(r + ""); + if (originalPromise !== void 0) { + originalPromise._attachExtraTrace(trace); } + resolver.promise._reject(r, trace); } - Promise._cast = Promise$_Cast; + function Promise$_progressFromThenable(v) { + if (called) return; + var promise = resolver.promise; + if (typeof promise._progress === "function") { + promise._progress(v); + } + } +} + +Promise._cast = Promise$_Cast; }; -},{"./errors.js":9,"./util.js":38}],37:[function(require,module,exports){ +},{"./errors.js":9,"./util.js":37}],36:[function(require,module,exports){ /** * Copyright (c) 2014 Petka Antonov * @@ -4830,99 +4764,88 @@ module.exports = function(Promise, INTERNAL) { * */ "use strict"; - var global = require("./global.js"); -var setTimeout = function(fn, time) { +var setTimeout = function(fn, ms) { var $_len = arguments.length;var args = new Array($_len - 2); for(var $_i = 2; $_i < $_len; ++$_i) {args[$_i - 2] = arguments[$_i];} - global.setTimeout(function() { + global.setTimeout(function(){ fn.apply(void 0, args); - }, time); + }, ms); }; -var pass = {}; -global.setTimeout( function(_) { - if(_ === pass) { - setTimeout = global.setTimeout; - } -}, 1, pass); - module.exports = function(Promise, INTERNAL) { - var util = require("./util.js"); - var errors = require("./errors.js"); - var apiRejection = require("./errors_api_rejection")(Promise); - var TimeoutError = Promise.TimeoutError; - - var afterTimeout = function Promise$_afterTimeout(promise, message, ms) { - if (!promise.isPending()) return; - if (typeof message !== "string") { - message = "operation timed out after" + " " + ms + " ms" - } - var err = new TimeoutError(message); - errors.markAsOriginatingFromRejection(err); - promise._attachExtraTrace(err); - promise._rejectUnchecked(err); - }; +var util = require("./util.js"); +var errors = require("./errors.js"); +var apiRejection = require("./errors_api_rejection")(Promise); +var TimeoutError = Promise.TimeoutError; - var afterDelay = function Promise$_afterDelay(value, promise) { - promise._fulfill(value); - }; +var afterTimeout = function Promise$_afterTimeout(promise, message, ms) { + if (!promise.isPending()) return; + if (typeof message !== "string") { + message = "operation timed out after" + " " + ms + " ms" + } + var err = new TimeoutError(message); + errors.markAsOriginatingFromRejection(err); + promise._attachExtraTrace(err); + promise._rejectUnchecked(err); +}; - Promise.delay = function Promise$Delay(value, ms, caller) { - if (ms === void 0) { - ms = value; - value = void 0; - } - ms = +ms; - if (typeof caller !== "function") { - caller = Promise.delay; - } - var maybePromise = Promise._cast(value, caller, void 0); - var promise = new Promise(INTERNAL); +var afterDelay = function Promise$_afterDelay(value, promise) { + promise._fulfill(value); +}; - if (Promise.is(maybePromise)) { - if (maybePromise._isBound()) { - promise._setBoundTo(maybePromise._boundTo); - } - if (maybePromise._cancellable()) { - promise._setCancellable(); - promise._cancellationParent = maybePromise; - } - promise._setTrace(caller, maybePromise); - promise._follow(maybePromise); - return promise.then(function(value) { - return Promise.delay(value, ms); - }); +var delay = Promise.delay = function Promise$Delay(value, ms) { + if (ms === void 0) { + ms = value; + value = void 0; + } + ms = +ms; + var maybePromise = Promise._cast(value, void 0); + var promise = new Promise(INTERNAL); + + if (maybePromise instanceof Promise) { + if (maybePromise._isBound()) { + promise._setBoundTo(maybePromise._boundTo); } - else { - promise._setTrace(caller, void 0); - setTimeout(afterDelay, ms, value, promise); + if (maybePromise._cancellable()) { + promise._setCancellable(); + promise._cancellationParent = maybePromise; } - return promise; - }; + promise._setTrace(maybePromise); + promise._follow(maybePromise); + return promise.then(function(value) { + return Promise.delay(value, ms); + }); + } + else { + promise._setTrace(void 0); + setTimeout(afterDelay, ms, value, promise); + } + return promise; +}; - Promise.prototype.delay = function Promise$delay(ms) { - return Promise.delay(this, ms, this.delay); - }; +Promise.prototype.delay = function Promise$delay(ms) { + return delay(this, ms); +}; - Promise.prototype.timeout = function Promise$timeout(ms, message) { - ms = +ms; +Promise.prototype.timeout = function Promise$timeout(ms, message) { + ms = +ms; - var ret = new Promise(INTERNAL); - ret._setTrace(this.timeout, this); + var ret = new Promise(INTERNAL); + ret._setTrace(this); - if (this._isBound()) ret._setBoundTo(this._boundTo); - if (this._cancellable()) { - ret._setCancellable(); - ret._cancellationParent = this; - } - ret._follow(this); - setTimeout(afterTimeout, ms, ret, message, ms); - return ret; - }; + if (this._isBound()) ret._setBoundTo(this._boundTo); + if (this._cancellable()) { + ret._setCancellable(); + ret._cancellationParent = this; + } + ret._follow(this); + setTimeout(afterTimeout, ms, ret, message, ms); + return ret; +}; }; -},{"./errors.js":9,"./errors_api_rejection":10,"./global.js":15,"./util.js":38}],38:[function(require,module,exports){ +},{"./errors.js":9,"./errors_api_rejection":10,"./global.js":15,"./util.js":37}],37:[function(require,module,exports){ /** * Copyright (c) 2014 Petka Antonov * diff --git a/package.json b/package.json index f3f7ae3af..337497818 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "bluebird", "description": "Full featured Promises/A+ implementation with exceptionally good performance", - "version": "1.1.1", + "version": "1.2.0", "keywords": [ "promise", "performance",