diff --git a/resource/bluebird.js b/resource/bluebird.js index 9e2ae6677..a7e60ec99 100644 --- a/resource/bluebird.js +++ b/resource/bluebird.js @@ -23,7 +23,7 @@ * */ /** - * bluebird build version 3.3.4 + * bluebird build version 3.4.7 * Features enabled: core, race, call_get, generators, map, nodeify, promisify, props, reduce, settle, some, using, timers, filter, any, each */ !function(e){ @@ -137,6 +137,7 @@ var Queue = _dereq_("./queue"); var util = _dereq_("./util"); function Async() { + this._customScheduler = false; this._isTickUsed = false; this._lateQueue = new Queue(16); this._normalQueue = new Queue(16); @@ -149,6 +150,17 @@ function Async() { this._schedule = schedule; } +Async.prototype.setScheduler = function(fn) { + var prev = this._schedule; + this._schedule = fn; + this._customScheduler = true; + return prev; +}; + +Async.prototype.hasCustomScheduler = function() { + return this._customScheduler; +}; + Async.prototype.enableTrampoline = function() { this._trampolineEnabled = true; }; @@ -245,11 +257,6 @@ if (!util.hasDevTools) { }; } -Async.prototype.invokeFirst = function (fn, receiver, arg) { - this._normalQueue.unshift(fn, receiver, arg); - this._queueTick(); -}; - Async.prototype._drainQueue = function(queue) { while (queue.length() > 0) { var fn = queue.shift(); @@ -504,7 +511,7 @@ Promise.prototype["break"] = Promise.prototype.cancel = function() { var promise = this; var child = promise; - while (promise.isCancellable()) { + while (promise._isCancellable()) { if (!promise._cancelBy(child)) { if (child._isFollowing()) { child._followee().cancel(); @@ -515,7 +522,7 @@ Promise.prototype["break"] = Promise.prototype.cancel = function() { } var parent = promise._cancellationParent; - if (parent == null || !parent.isCancellable()) { + if (parent == null || !parent._isCancellable()) { if (promise._isFollowing()) { promise._followee().cancel(); } else { @@ -524,6 +531,7 @@ Promise.prototype["break"] = Promise.prototype.cancel = function() { break; } else { if (promise._isFollowing()) promise._followee().cancel(); + promise._setWillBeCancelled(); child = promise; promise = parent; } @@ -561,8 +569,7 @@ Promise.prototype._cancelBranched = function() { }; Promise.prototype._cancel = function() { - if (!this.isCancellable()) return; - + if (!this._isCancellable()) return; this._setCancelled(); async.invoke(this._cancelPromises, this, undefined); }; @@ -575,6 +582,10 @@ Promise.prototype._unsetOnCancel = function() { this._onCancelField = undefined; }; +Promise.prototype._isCancellable = function() { + return this.isPending() && !this._isCancelled(); +}; + Promise.prototype.isCancellable = function() { return this.isPending() && !this.isCancelled(); }; @@ -606,7 +617,7 @@ Promise.prototype._invokeOnCancel = function() { }; Promise.prototype._invokeInternalOnCancel = function() { - if (this.isCancellable()) { + if (this._isCancellable()) { this._doInvokeOnCancel(this._onCancel(), true); this._unsetOnCancel(); } @@ -745,6 +756,8 @@ var unhandledRejectionHandled; var possiblyUnhandledRejection; var bluebirdFramePattern = /[\\\/]bluebird[\\\/]js[\\\/](release|debug|instrumented)/; +var nodeFramePattern = /\((?:timers\.js):\d+:\d+\)/; +var parseLinePattern = /[\/<\(](.+?):(\d+):(\d+)\)?\s*$/; var stackFramePattern = null; var formatStack = null; var indentStackFrames = false; @@ -832,14 +845,16 @@ Promise.prototype._warn = function(message, shouldUseOwnTrace, promise) { Promise.onPossiblyUnhandledRejection = function (fn) { var domain = getDomain(); possiblyUnhandledRejection = - typeof fn === "function" ? (domain === null ? fn : domain.bind(fn)) + typeof fn === "function" ? (domain === null ? + fn : util.domainBind(domain, fn)) : undefined; }; Promise.onUnhandledRejectionHandled = function (fn) { var domain = getDomain(); unhandledRejectionHandled = - typeof fn === "function" ? (domain === null ? fn : domain.bind(fn)) + typeof fn === "function" ? (domain === null ? + fn : util.domainBind(domain, fn)) : undefined; }; @@ -875,14 +890,37 @@ Promise.hasLongStackTraces = function () { var fireDomEvent = (function() { try { - var event = document.createEvent("CustomEvent"); - event.initCustomEvent("testingtheevent", false, true, {}); - util.global.dispatchEvent(event); - return function(name, event) { - var domEvent = document.createEvent("CustomEvent"); - domEvent.initCustomEvent(name.toLowerCase(), false, true, event); - return !util.global.dispatchEvent(domEvent); - }; + if (typeof CustomEvent === "function") { + var event = new CustomEvent("CustomEvent"); + util.global.dispatchEvent(event); + return function(name, event) { + var domEvent = new CustomEvent(name.toLowerCase(), { + detail: event, + cancelable: true + }); + return !util.global.dispatchEvent(domEvent); + }; + } else if (typeof Event === "function") { + var event = new Event("CustomEvent"); + util.global.dispatchEvent(event); + return function(name, event) { + var domEvent = new Event(name.toLowerCase(), { + cancelable: true + }); + domEvent.detail = event; + return !util.global.dispatchEvent(domEvent); + }; + } else { + var event = document.createEvent("CustomEvent"); + event.initCustomEvent("testingtheevent", false, true, {}); + util.global.dispatchEvent(event); + return function(name, event) { + var domEvent = document.createEvent("CustomEvent"); + domEvent.initCustomEvent(name.toLowerCase(), false, true, + event); + return !util.global.dispatchEvent(domEvent); + }; + } } catch (e) {} return function() { return false; @@ -998,6 +1036,7 @@ Promise.config = function(opts) { Promise.prototype._fireEvent = defaultFireEvent; } } + return Promise; }; function defaultFireEvent() { return false; } @@ -1039,7 +1078,7 @@ function cancellationExecute(executor, resolve, reject) { } function cancellationAttachCancellationCallback(onCancel) { - if (!this.isCancellable()) return this; + if (!this._isCancellable()) return this; var previousOnCancel = this._onCancel(); if (previousOnCancel !== undefined) { @@ -1127,12 +1166,44 @@ function checkForgottenReturns(returnValue, promiseCreated, name, promise, if (returnValue === undefined && promiseCreated !== null && wForgottenReturn) { if (parent !== undefined && parent._returnedNonUndefined()) return; - var bitField = promise._bitField; - if ((bitField & 65535) === 0) return; + if ((promise._bitField & 65535) === 0) return; if (name) name = name + " "; + var handlerLine = ""; + var creatorLine = ""; + if (promiseCreated._trace) { + var traceLines = promiseCreated._trace.stack.split("\n"); + var stack = cleanStack(traceLines); + for (var i = stack.length - 1; i >= 0; --i) { + var line = stack[i]; + if (!nodeFramePattern.test(line)) { + var lineMatches = line.match(parseLinePattern); + if (lineMatches) { + handlerLine = "at " + lineMatches[1] + + ":" + lineMatches[2] + ":" + lineMatches[3] + " "; + } + break; + } + } + + if (stack.length > 0) { + var firstUserLine = stack[0]; + for (var i = 0; i < traceLines.length; ++i) { + + if (traceLines[i] === firstUserLine) { + if (i > 0) { + creatorLine = "\n" + traceLines[i - 1]; + } + break; + } + } + + } + } var msg = "a promise was created in a " + name + - "handler but was not returned from it"; + "handler " + handlerLine + "but was not returned from it, " + + "see http://goo.gl/rRqMUw" + + creatorLine; promise._warn(msg, true, promiseCreated); } } @@ -1236,7 +1307,7 @@ function stackFramesAsArray(error) { break; } } - if (i > 0) { + if (i > 0 && error.name != "SyntaxError") { stack = stack.slice(i); } return stack; @@ -1249,7 +1320,7 @@ function parseStackAndMessage(error) { ? stackFramesAsArray(error) : [" (No stack trace)"]; return { message: message, - stack: cleanStack(stack) + stack: error.name == "SyntaxError" ? stack : cleanStack(stack) }; } @@ -1654,8 +1725,8 @@ function PromiseMapSeries(promises, fn) { } Promise.prototype.each = function (fn) { - return this.mapSeries(fn) - ._then(promiseAllThis, undefined, undefined, this, undefined); + return PromiseReduce(this, fn, INTERNAL, 0) + ._then(promiseAllThis, undefined, undefined, this, undefined); }; Promise.prototype.mapSeries = function (fn) { @@ -1663,13 +1734,14 @@ Promise.prototype.mapSeries = function (fn) { }; Promise.each = function (promises, fn) { - return PromiseMapSeries(promises, fn) - ._then(promiseAllThis, undefined, undefined, promises, undefined); + return PromiseReduce(promises, fn, INTERNAL, 0) + ._then(promiseAllThis, undefined, undefined, promises, undefined); }; Promise.mapSeries = PromiseMapSeries; }; + },{}],12:[function(_dereq_,module,exports){ "use strict"; var es5 = _dereq_("./es5"); @@ -1946,7 +2018,7 @@ function finallyHandler(reasonOrValue) { var maybePromise = tryConvertToPromise(ret, promise); if (maybePromise instanceof Promise) { if (this.cancelPromise != null) { - if (maybePromise.isCancelled()) { + if (maybePromise._isCancelled()) { var reason = new CancellationError("late cancellation observer"); promise._attachExtraTrace(reason); @@ -2030,9 +2102,18 @@ function promiseFromYieldHandler(value, yieldHandlers, traceParent) { } function PromiseSpawn(generatorFunction, receiver, yieldHandler, stack) { - var promise = this._promise = new Promise(INTERNAL); - promise._captureStackTrace(); - promise._setOnCancel(this); + if (debug.cancellation()) { + var internal = new Promise(INTERNAL); + var _finallyPromise = this._finallyPromise = new Promise(INTERNAL); + this._promise = internal.lastly(function() { + return _finallyPromise; + }); + internal._captureStackTrace(); + internal._setOnCancel(this); + } else { + var promise = this._promise = new Promise(INTERNAL); + promise._captureStackTrace(); + } this._stack = stack; this._generatorFunction = generatorFunction; this._receiver = receiver; @@ -2041,6 +2122,7 @@ function PromiseSpawn(generatorFunction, receiver, yieldHandler, stack) { ? [yieldHandler].concat(yieldHandlers) : yieldHandlers; this._yieldedPromise = null; + this._cancellationPhase = false; } util.inherits(PromiseSpawn, Proxyable); @@ -2050,6 +2132,10 @@ PromiseSpawn.prototype._isResolved = function() { PromiseSpawn.prototype._cleanup = function() { this._promise = this._generator = null; + if (debug.cancellation() && this._finallyPromise !== null) { + this._finallyPromise._fulfill(); + this._finallyPromise = null; + } }; PromiseSpawn.prototype._promiseCancelled = function() { @@ -2066,22 +2152,15 @@ PromiseSpawn.prototype._promiseCancelled = function() { result = tryCatch(this._generator["throw"]).call(this._generator, reason); this._promise._popContext(); - if (result === errorObj && result.e === reason) { - result = null; - } } else { this._promise._pushContext(); result = tryCatch(this._generator["return"]).call(this._generator, undefined); this._promise._popContext(); } - var promise = this._promise; - this._cleanup(); - if (result === errorObj) { - promise._rejectCallback(result.e, false); - } else { - promise.cancel(); - } + this._cancellationPhase = true; + this._yieldedPromise = null; + this._continue(result); }; PromiseSpawn.prototype._promiseFulfilled = function(value) { @@ -2106,7 +2185,6 @@ PromiseSpawn.prototype._resultCancelled = function() { if (this._yieldedPromise instanceof Promise) { var promise = this._yieldedPromise; this._yieldedPromise = null; - this._promiseCancelled(); promise.cancel(); } }; @@ -2126,13 +2204,21 @@ PromiseSpawn.prototype._continue = function (result) { var promise = this._promise; if (result === errorObj) { this._cleanup(); - return promise._rejectCallback(result.e, false); + if (this._cancellationPhase) { + return promise.cancel(); + } else { + return promise._rejectCallback(result.e, false); + } } var value = result.value; if (result.done === true) { this._cleanup(); - return promise._resolveCallback(value); + if (this._cancellationPhase) { + return promise.cancel(); + } else { + return promise._resolveCallback(value); + } } else { var maybePromise = tryConvertToPromise(value, this._promise); if (!(maybePromise instanceof Promise)) { @@ -2158,9 +2244,13 @@ PromiseSpawn.prototype._continue = function (result) { this._yieldedPromise = maybePromise; maybePromise._proxy(this, null); } else if (((bitField & 33554432) !== 0)) { - this._promiseFulfilled(maybePromise._value()); + Promise._async.invoke( + this._promiseFulfilled, this, maybePromise._value() + ); } else if (((bitField & 16777216) !== 0)) { - this._promiseRejected(maybePromise._reason()); + Promise._async.invoke( + this._promiseRejected, this, maybePromise._reason() + ); } else { this._promiseCancelled(); } @@ -2207,7 +2297,8 @@ Promise.spawn = function (generatorFunction) { },{"./errors":12,"./util":36}],17:[function(_dereq_,module,exports){ "use strict"; module.exports = -function(Promise, PromiseArray, tryConvertToPromise, INTERNAL) { +function(Promise, PromiseArray, tryConvertToPromise, INTERNAL, async, + getDomain) { var util = _dereq_("./util"); var canEvaluate = util.canEvaluate; var tryCatch = util.tryCatch; @@ -2249,25 +2340,35 @@ if (canEvaluate) { var name = "Holder$" + total; - var code = "return function(tryCatch, errorObj, Promise) { \n\ + var code = "return function(tryCatch, errorObj, Promise, async) { \n\ 'use strict'; \n\ function [TheName](fn) { \n\ [TheProperties] \n\ this.fn = fn; \n\ + this.asyncNeeded = true; \n\ this.now = 0; \n\ } \n\ + \n\ + [TheName].prototype._callFunction = function(promise) { \n\ + promise._pushContext(); \n\ + var ret = tryCatch(this.fn)([ThePassedArguments]); \n\ + promise._popContext(); \n\ + if (ret === errorObj) { \n\ + promise._rejectCallback(ret.e, false); \n\ + } else { \n\ + promise._resolveCallback(ret); \n\ + } \n\ + }; \n\ + \n\ [TheName].prototype.checkFulfillment = function(promise) { \n\ var now = ++this.now; \n\ if (now === [TheTotal]) { \n\ - promise._pushContext(); \n\ - var callback = this.fn; \n\ - var ret = tryCatch(callback)([ThePassedArguments]); \n\ - promise._popContext(); \n\ - if (ret === errorObj) { \n\ - promise._rejectCallback(ret.e, false); \n\ + if (this.asyncNeeded) { \n\ + async.invoke(this._callFunction, this, promise); \n\ } else { \n\ - promise._resolveCallback(ret); \n\ + this._callFunction(promise); \n\ } \n\ + \n\ } \n\ }; \n\ \n\ @@ -2276,7 +2377,7 @@ if (canEvaluate) { }; \n\ \n\ return [TheName]; \n\ - }(tryCatch, errorObj, Promise); \n\ + }(tryCatch, errorObj, Promise, async); \n\ "; code = code.replace(/\[TheName\]/g, name) @@ -2285,8 +2386,8 @@ if (canEvaluate) { .replace(/\[TheProperties\]/g, assignment) .replace(/\[CancellationCode\]/g, cancellationCode); - return new Function("tryCatch", "errorObj", "Promise", code) - (tryCatch, errorObj, Promise); + return new Function("tryCatch", "errorObj", "Promise", "async", code) + (tryCatch, errorObj, Promise, async); }; var holderClasses = []; @@ -2327,6 +2428,7 @@ Promise.join = function () { maybePromise._then(callbacks[i], reject, undefined, ret, holder); promiseSetters[i](maybePromise, holder); + holder.asyncNeeded = false; } else if (((bitField & 33554432) !== 0)) { callbacks[i].call(ret, maybePromise._value(), holder); @@ -2339,7 +2441,14 @@ Promise.join = function () { callbacks[i].call(ret, maybePromise, holder); } } + if (!ret._isFateSealed()) { + if (holder.asyncNeeded) { + var domain = getDomain(); + if (domain !== null) { + holder.fn = util.domainBind(domain, holder.fn); + } + } ret._setAsyncGuaranteed(); ret._setOnCancel(holder); } @@ -2367,23 +2476,27 @@ var getDomain = Promise._getDomain; var util = _dereq_("./util"); var tryCatch = util.tryCatch; var errorObj = util.errorObj; -var EMPTY_ARRAY = []; +var async = Promise._async; function MappingPromiseArray(promises, fn, limit, _filter) { this.constructor$(promises); this._promise._captureStackTrace(); var domain = getDomain(); - this._callback = domain === null ? fn : domain.bind(fn); + this._callback = domain === null ? fn : util.domainBind(domain, fn); this._preservedValues = _filter === INTERNAL ? new Array(this.length()) : null; this._limit = limit; this._inFlight = 0; - this._queue = limit >= 1 ? [] : EMPTY_ARRAY; - this._init$(undefined, -2); + this._queue = []; + async.invoke(this._asyncInit, this, undefined); } util.inherits(MappingPromiseArray, PromiseArray); +MappingPromiseArray.prototype._asyncInit = function() { + this._init$(undefined, -2); +}; + MappingPromiseArray.prototype._init = function () {}; MappingPromiseArray.prototype._promiseFulfilled = function (value, index) { @@ -2489,9 +2602,22 @@ function map(promises, fn, options, _filter) { if (typeof fn !== "function") { return apiRejection("expecting a function but got " + util.classString(fn)); } - var limit = typeof options === "object" && options !== null - ? options.concurrency - : 0; + + var limit = 0; + if (options !== undefined) { + if (typeof options === "object" && options !== null) { + if (typeof options.concurrency !== "number") { + return Promise.reject( + new TypeError("'concurrency' must be a number but it is " + + util.classString(options.concurrency))); + } + limit = options.concurrency; + } else { + return Promise.reject(new TypeError( + "options argument must be an object but it is " + + util.classString(options))); + } + } limit = typeof limit === "number" && isFinite(limit) && limit >= 1 ? limit : 0; return new MappingPromiseArray(promises, fn, limit, _filter).promise(); @@ -2775,7 +2901,8 @@ Promise.prototype.caught = Promise.prototype["catch"] = function (fn) { if (util.isObject(item)) { catchInstances[j++] = item; } else { - return apiRejection("expecting an object but got " + util.classString(item)); + return apiRejection("expecting an object but got " + + "A catch statement predicate " + util.classString(item)); } } catchInstances.length = j; @@ -2845,6 +2972,8 @@ Promise.prototype.error = function (fn) { return this.caught(util.originatesFromRejection, fn); }; +Promise.getNewLibraryCopy = module.exports; + Promise.is = function (val) { return val instanceof Promise; }; @@ -2890,9 +3019,7 @@ Promise.setScheduler = function(fn) { if (typeof fn !== "function") { throw new TypeError("expecting a function but got " + util.classString(fn)); } - var prev = async._schedule; - async._schedule = fn; - return prev; + return async.setScheduler(fn); }; Promise.prototype._then = function ( @@ -2939,7 +3066,8 @@ Promise.prototype._then = function ( async.invoke(settler, target, { handler: domain === null ? handler - : (typeof handler === "function" && domain.bind(handler)), + : (typeof handler === "function" && + util.domainBind(domain, handler)), promise: promise, receiver: receiver, value: value @@ -3000,7 +3128,12 @@ Promise.prototype._setCancelled = function() { this._fireEvent("promiseCancelled", this); }; +Promise.prototype._setWillBeCancelled = function() { + this._bitField = this._bitField | 8388608; +}; + Promise.prototype._setAsyncGuaranteed = function() { + if (async.hasCustomScheduler()) return; this._bitField = this._bitField | 134217728; }; @@ -3070,11 +3203,11 @@ Promise.prototype._addCallbacks = function ( this._receiver0 = receiver; if (typeof fulfill === "function") { this._fulfillmentHandler0 = - domain === null ? fulfill : domain.bind(fulfill); + domain === null ? fulfill : util.domainBind(domain, fulfill); } if (typeof reject === "function") { this._rejectionHandler0 = - domain === null ? reject : domain.bind(reject); + domain === null ? reject : util.domainBind(domain, reject); } } else { var base = index * 4 - 4; @@ -3082,11 +3215,11 @@ Promise.prototype._addCallbacks = function ( this[base + 3] = receiver; if (typeof fulfill === "function") { this[base + 0] = - domain === null ? fulfill : domain.bind(fulfill); + domain === null ? fulfill : util.domainBind(domain, fulfill); } if (typeof reject === "function") { this[base + 1] = - domain === null ? reject : domain.bind(reject); + domain === null ? reject : util.domainBind(domain, reject); } } this._setLength(index + 1); @@ -3403,23 +3536,24 @@ _dereq_("./cancel")(Promise, PromiseArray, apiRejection, debug); _dereq_("./direct_resolve")(Promise); _dereq_("./synchronous_inspection")(Promise); _dereq_("./join")( - Promise, PromiseArray, tryConvertToPromise, INTERNAL, debug); + Promise, PromiseArray, tryConvertToPromise, INTERNAL, async, getDomain); Promise.Promise = Promise; +Promise.version = "3.4.7"; _dereq_('./map.js')(Promise, PromiseArray, apiRejection, tryConvertToPromise, INTERNAL, debug); +_dereq_('./call_get.js')(Promise); _dereq_('./using.js')(Promise, apiRejection, tryConvertToPromise, createContext, INTERNAL, debug); _dereq_('./timers.js')(Promise, INTERNAL, debug); _dereq_('./generators.js')(Promise, apiRejection, INTERNAL, tryConvertToPromise, Proxyable, debug); _dereq_('./nodeify.js')(Promise); -_dereq_('./call_get.js')(Promise); +_dereq_('./promisify.js')(Promise, INTERNAL); _dereq_('./props.js')(Promise, PromiseArray, tryConvertToPromise, apiRejection); _dereq_('./race.js')(Promise, INTERNAL, tryConvertToPromise, apiRejection); _dereq_('./reduce.js')(Promise, PromiseArray, apiRejection, tryConvertToPromise, INTERNAL, debug); _dereq_('./settle.js')(Promise, PromiseArray, debug); _dereq_('./some.js')(Promise, PromiseArray, apiRejection); -_dereq_('./promisify.js')(Promise, INTERNAL); -_dereq_('./any.js')(Promise); -_dereq_('./each.js')(Promise, INTERNAL); _dereq_('./filter.js')(Promise, INTERNAL); +_dereq_('./each.js')(Promise, INTERNAL); +_dereq_('./any.js')(Promise); util.toFastProperties(Promise); util.toFastProperties(Promise.prototype); @@ -3574,7 +3708,7 @@ PromiseArray.prototype._resolve = function (value) { }; PromiseArray.prototype._cancel = function() { - if (this._isResolved() || !this._promise.isCancellable()) return; + if (this._isResolved() || !this._promise._isCancellable()) return; this._values = null; this._promise._cancel(); }; @@ -4094,23 +4228,6 @@ Queue.prototype._pushOne = function (arg) { this._length = length + 1; }; -Queue.prototype._unshiftOne = function(value) { - var capacity = this._capacity; - this._checkCapacity(this.length() + 1); - var front = this._front; - var i = (((( front - 1 ) & - ( capacity - 1) ) ^ capacity ) - capacity ); - this[i] = value; - this._front = i; - this._length = this.length() + 1; -}; - -Queue.prototype.unshift = function(fn, receiver, arg) { - this._unshiftOne(arg); - this._unshiftOne(receiver); - this._unshiftOne(fn); -}; - Queue.prototype.push = function (fn, receiver, arg) { var length = this.length() + 3; if (this._willBeOverCapacity(length)) { @@ -4225,27 +4342,37 @@ var tryCatch = util.tryCatch; function ReductionPromiseArray(promises, fn, initialValue, _each) { this.constructor$(promises); var domain = getDomain(); - this._fn = domain === null ? fn : domain.bind(fn); + this._fn = domain === null ? fn : util.domainBind(domain, fn); if (initialValue !== undefined) { initialValue = Promise.resolve(initialValue); initialValue._attachCancellationCallback(this); } this._initialValue = initialValue; this._currentCancellable = null; - this._eachValues = _each === INTERNAL ? [] : undefined; + if(_each === INTERNAL) { + this._eachValues = Array(this._length); + } else if (_each === 0) { + this._eachValues = null; + } else { + this._eachValues = undefined; + } this._promise._captureStackTrace(); this._init$(undefined, -5); } util.inherits(ReductionPromiseArray, PromiseArray); ReductionPromiseArray.prototype._gotAccum = function(accum) { - if (this._eachValues !== undefined && accum !== INTERNAL) { + if (this._eachValues !== undefined && + this._eachValues !== null && + accum !== INTERNAL) { this._eachValues.push(accum); } }; ReductionPromiseArray.prototype._eachComplete = function(value) { - this._eachValues.push(value); + if (this._eachValues !== null) { + this._eachValues.push(value); + } return this._eachValues; }; @@ -4381,16 +4508,23 @@ var schedule; var noAsyncScheduler = function() { throw new Error("No async scheduler available\u000a\u000a See http://goo.gl/MqrFmX\u000a"); }; +var NativePromise = util.getNativePromise(); if (util.isNode && typeof MutationObserver === "undefined") { var GlobalSetImmediate = global.setImmediate; var ProcessNextTick = process.nextTick; schedule = util.isRecentNode ? function(fn) { GlobalSetImmediate.call(global, fn); } : function(fn) { ProcessNextTick.call(process, fn); }; +} else if (typeof NativePromise === "function" && + typeof NativePromise.resolve === "function") { + var nativePromise = NativePromise.resolve(); + schedule = function(fn) { + nativePromise.then(fn); + }; } else if ((typeof MutationObserver !== "undefined") && !(typeof window !== "undefined" && window.navigator && - window.navigator.standalone)) { + (window.navigator.standalone || window.cordova))) { schedule = (function() { var div = document.createElement("div"); var opts = {attributes: true}; @@ -4398,23 +4532,23 @@ if (util.isNode && typeof MutationObserver === "undefined") { var div2 = document.createElement("div"); var o2 = new MutationObserver(function() { div.classList.toggle("foo"); - toggleScheduled = false; + toggleScheduled = false; }); o2.observe(div2, opts); var scheduleToggle = function() { if (toggleScheduled) return; - toggleScheduled = true; - div2.classList.toggle("foo"); - }; + toggleScheduled = true; + div2.classList.toggle("foo"); + }; - return function schedule(fn) { - var o = new MutationObserver(function() { - o.disconnect(); - fn(); - }); - o.observe(div, opts); - scheduleToggle(); + return function schedule(fn) { + var o = new MutationObserver(function() { + o.disconnect(); + fn(); + }); + o.observe(div, opts); + scheduleToggle(); }; })(); } else if (typeof setImmediate !== "undefined") { @@ -4676,13 +4810,20 @@ var isResolved = PromiseInspection.prototype.isResolved = function () { return (this._bitField & 50331648) !== 0; }; -PromiseInspection.prototype.isCancelled = -Promise.prototype._isCancelled = function() { +PromiseInspection.prototype.isCancelled = function() { + return (this._bitField & 8454144) !== 0; +}; + +Promise.prototype.__isCancelled = function() { return (this._bitField & 65536) === 65536; }; +Promise.prototype._isCancelled = function() { + return this._target().__isCancelled(); +}; + Promise.prototype.isCancelled = function() { - return this._target()._isCancelled(); + return (this._target()._bitField & 8454144) !== 0; }; Promise.prototype.isPending = function() { @@ -4772,7 +4913,11 @@ function getThen(obj) { var hasProp = {}.hasOwnProperty; function isAnyBluebirdPromise(obj) { - return hasProp.call(obj, "_promise0"); + try { + return hasProp.call(obj, "_promise0"); + } catch (e) { + return false; + } } function doThenable(x, then, context) { @@ -4837,6 +4982,7 @@ var delay = Promise.delay = function (ms, value) { if (debug.cancellation()) { ret._setOnCancel(new HandleWrapper(handle)); } + ret._captureStackTrace(); } ret._setAsyncGuaranteed(); return ret; @@ -4910,6 +5056,7 @@ module.exports = function (Promise, apiRejection, tryConvertToPromise, var inherits = _dereq_("./util").inherits; var errorObj = util.errorObj; var tryCatch = util.tryCatch; + var NULL = {}; function thrower(e) { setTimeout(function(){throw e;}, 0); @@ -4970,14 +5117,14 @@ module.exports = function (Promise, apiRejection, tryConvertToPromise, if (this.promise().isFulfilled()) { return this.promise().value(); } - return null; + return NULL; }; Disposer.prototype.tryDispose = function(inspection) { var resource = this.resource(); var context = this._context; if (context !== undefined) context._pushContext(); - var ret = resource !== null + var ret = resource !== NULL ? this.doDispose(resource, inspection) : null; if (context !== undefined) context._popContext(); this._promise._unsetDisposable(); @@ -5329,7 +5476,7 @@ function toFastProperties(obj) { var l = 8; while (l--) new FakeConstructor(); return obj; - eval(obj); + //eval(obj); } var rident = /^[a-z$_][a-z$_0-9]*$/i; @@ -5441,8 +5588,26 @@ if (typeof Symbol !== "undefined" && Symbol.iterator) { var isNode = typeof process !== "undefined" && classString(process).toLowerCase() === "[object process]"; -function env(key, def) { - return isNode ? process.env[key] : def; +var hasEnvVariables = typeof process !== "undefined" && + typeof process.env !== "undefined"; + +function env(key) { + return hasEnvVariables ? process.env[key] : undefined; +} + +function getNativePromise() { + if (typeof Promise === "function") { + try { + var promise = new Promise(function(){}); + if ({}.toString.call(promise) === "[object Promise]") { + return Promise; + } + } catch (e) {} + } +} + +function domainBind(self, cb) { + return self.bind(cb); } var ret = { @@ -5475,8 +5640,11 @@ var ret = { hasDevTools: typeof chrome !== "undefined" && chrome && typeof chrome.loadTimes === "function", isNode: isNode, + hasEnvVariables: hasEnvVariables, env: env, - global: globalObject + global: globalObject, + getNativePromise: getNativePromise, + domainBind: domainBind }; ret.isRecentNode = ret.isNode && (function() { var version = process.versions.node.split(".").map(Number);