Comparing version 3.0.0 to 3.0.1
{ | ||
"name": "when", | ||
"version": "3.0.0", | ||
"version": "3.0.1", | ||
"main": "when.js", | ||
@@ -5,0 +5,0 @@ "moduleType": ["amd", "node"], |
@@ -0,1 +1,7 @@ | ||
### 3.0.1 | ||
* [API doc](docs/api.md) updates and fixes | ||
* Improvements to unhandled rejection long stack trace filtering | ||
* Internal performance improvements | ||
### 3.0.0 | ||
@@ -2,0 +8,0 @@ |
@@ -185,3 +185,2 @@ !function(e){"object"==typeof exports?module.exports=e():"function"==typeof define&&define.amd?define(e):"undefined"!=typeof window?window.Promise=e():"undefined"!=typeof global?global.Promise=e():"undefined"!=typeof self&&(self.Promise=e())}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | ||
var foreverPendingPromise; | ||
var promiseCycleError; | ||
var tasks = environment.scheduler; | ||
@@ -351,3 +350,3 @@ | ||
if (maybeThenable(x)) { | ||
resolveOne(resolver, results, getHandlerChecked(x), i); | ||
resolveOne(resolver, results, getHandlerThenable(x), i); | ||
} else { | ||
@@ -424,3 +423,4 @@ results[i] = x; | ||
/** | ||
* Get an appropriate handler for x | ||
* Get an appropriate handler for x, checking for untrusted thenables | ||
* and promise graph cycles. | ||
* @private | ||
@@ -433,3 +433,3 @@ * @param {*} x | ||
if(x instanceof Promise) { | ||
return getHandlerPromise(x, h); | ||
return getHandlerChecked(x, h); | ||
} | ||
@@ -439,12 +439,27 @@ return maybeThenable(x) ? getHandlerUntrusted(x) : new FulfilledHandler(x); | ||
function getHandlerChecked(x, h) { | ||
return x instanceof Promise | ||
? getHandlerPromise(x, h) : getHandlerUntrusted(x); | ||
/** | ||
* Get an appropriate handler for x, which must be either a thenable | ||
* @param {object} x | ||
* @returns {object} handler | ||
*/ | ||
function getHandlerThenable(x) { | ||
return x instanceof Promise ? x._handler.join() : getHandlerUntrusted(x); | ||
} | ||
function getHandlerPromise(x, h) { | ||
var h2 = x._handler.join(); | ||
return h === h2 ? promiseCycleError : h2; | ||
/** | ||
* Get x's handler, checking for cycles | ||
* @param {Promise} x | ||
* @param {object?} h handler to check for cycles | ||
* @returns {object} handler | ||
*/ | ||
function getHandlerChecked(x, h) { | ||
var xh = x._handler.join(); | ||
return h === xh ? promiseCycleHandler() : xh; | ||
} | ||
/** | ||
* Get a handler for potentially untrusted thenable x | ||
* @param {*} x | ||
* @returns {object} handler | ||
*/ | ||
function getHandlerUntrusted(x) { | ||
@@ -489,2 +504,6 @@ try { | ||
this.handler = handler; | ||
if(this._isMonitored()) { | ||
var trace = this._env.promiseMonitor.captureStack(); | ||
this.trace = handler._addTrace(trace); | ||
} | ||
} | ||
@@ -589,5 +608,2 @@ | ||
DelegateHandler.call(this, handler); | ||
if(this._isMonitored()) { | ||
this.trace = handler._addTrace(this._env.promiseMonitor.captureStack()); | ||
} | ||
} | ||
@@ -691,4 +707,2 @@ | ||
FulfilledHandler.prototype._addTrace = noop; | ||
/** | ||
@@ -700,8 +714,8 @@ * Handler for a rejected promise | ||
*/ | ||
function RejectedHandler(x, observed) { | ||
function RejectedHandler(x) { | ||
this.value = x; | ||
this.observed = false; | ||
if(this._isMonitored()) { | ||
this.observed = !!observed; | ||
this.key = this.observed ? -1 : this._env.promiseMonitor.startTrace(x); | ||
this.key = this._env.promiseMonitor.startTrace(x); | ||
} | ||
@@ -718,6 +732,6 @@ } | ||
if(this._isMonitored() && !this.observed) { | ||
this.observed = true; | ||
this._env.promiseMonitor.removeTrace(this.key); | ||
} | ||
this.observed = true; | ||
var x = typeof r === 'function' | ||
@@ -739,4 +753,7 @@ ? tryCatchReject(r, this.value, receiver) | ||
foreverPendingPromise = new InternalPromise(new Handler()); | ||
promiseCycleError = new RejectedHandler(new TypeError('Promise cycle'), true); | ||
function promiseCycleHandler() { | ||
return new RejectedHandler(new TypeError('Promise cycle')); | ||
} | ||
// Snapshot states | ||
@@ -743,0 +760,0 @@ |
@@ -34,2 +34,3 @@ /** @license MIT License (c) copyright 2011-2013 original author or authors */ | ||
for(var k in object) { | ||
++pending; | ||
resolveOne(object[k], k); | ||
@@ -43,6 +44,4 @@ } | ||
function resolveOne(x, k) { | ||
++pending; | ||
toPromise(x).then(function(x) { | ||
results[k] = x; | ||
if(--pending === 0) { | ||
@@ -49,0 +48,0 @@ resolve(results); |
@@ -11,3 +11,2 @@ /** @license MIT License (c) copyright 2010-2014 original author or authors */ | ||
var foreverPendingPromise; | ||
var promiseCycleError; | ||
var tasks = environment.scheduler; | ||
@@ -177,3 +176,3 @@ | ||
if (maybeThenable(x)) { | ||
resolveOne(resolver, results, getHandlerChecked(x), i); | ||
resolveOne(resolver, results, getHandlerThenable(x), i); | ||
} else { | ||
@@ -250,3 +249,4 @@ results[i] = x; | ||
/** | ||
* Get an appropriate handler for x | ||
* Get an appropriate handler for x, checking for untrusted thenables | ||
* and promise graph cycles. | ||
* @private | ||
@@ -259,3 +259,3 @@ * @param {*} x | ||
if(x instanceof Promise) { | ||
return getHandlerPromise(x, h); | ||
return getHandlerChecked(x, h); | ||
} | ||
@@ -265,12 +265,27 @@ return maybeThenable(x) ? getHandlerUntrusted(x) : new FulfilledHandler(x); | ||
function getHandlerChecked(x, h) { | ||
return x instanceof Promise | ||
? getHandlerPromise(x, h) : getHandlerUntrusted(x); | ||
/** | ||
* Get an appropriate handler for x, which must be either a thenable | ||
* @param {object} x | ||
* @returns {object} handler | ||
*/ | ||
function getHandlerThenable(x) { | ||
return x instanceof Promise ? x._handler.join() : getHandlerUntrusted(x); | ||
} | ||
function getHandlerPromise(x, h) { | ||
var h2 = x._handler.join(); | ||
return h === h2 ? promiseCycleError : h2; | ||
/** | ||
* Get x's handler, checking for cycles | ||
* @param {Promise} x | ||
* @param {object?} h handler to check for cycles | ||
* @returns {object} handler | ||
*/ | ||
function getHandlerChecked(x, h) { | ||
var xh = x._handler.join(); | ||
return h === xh ? promiseCycleHandler() : xh; | ||
} | ||
/** | ||
* Get a handler for potentially untrusted thenable x | ||
* @param {*} x | ||
* @returns {object} handler | ||
*/ | ||
function getHandlerUntrusted(x) { | ||
@@ -315,2 +330,6 @@ try { | ||
this.handler = handler; | ||
if(this._isMonitored()) { | ||
var trace = this._env.promiseMonitor.captureStack(); | ||
this.trace = handler._addTrace(trace); | ||
} | ||
} | ||
@@ -415,5 +434,2 @@ | ||
DelegateHandler.call(this, handler); | ||
if(this._isMonitored()) { | ||
this.trace = handler._addTrace(this._env.promiseMonitor.captureStack()); | ||
} | ||
} | ||
@@ -517,4 +533,2 @@ | ||
FulfilledHandler.prototype._addTrace = noop; | ||
/** | ||
@@ -526,8 +540,8 @@ * Handler for a rejected promise | ||
*/ | ||
function RejectedHandler(x, observed) { | ||
function RejectedHandler(x) { | ||
this.value = x; | ||
this.observed = false; | ||
if(this._isMonitored()) { | ||
this.observed = !!observed; | ||
this.key = this.observed ? -1 : this._env.promiseMonitor.startTrace(x); | ||
this.key = this._env.promiseMonitor.startTrace(x); | ||
} | ||
@@ -544,6 +558,6 @@ } | ||
if(this._isMonitored() && !this.observed) { | ||
this.observed = true; | ||
this._env.promiseMonitor.removeTrace(this.key); | ||
} | ||
this.observed = true; | ||
var x = typeof r === 'function' | ||
@@ -565,4 +579,7 @@ ? tryCatchReject(r, this.value, receiver) | ||
foreverPendingPromise = new InternalPromise(new Handler()); | ||
promiseCycleError = new RejectedHandler(new TypeError('Promise cycle'), true); | ||
function promiseCycleHandler() { | ||
return new RejectedHandler(new TypeError('Promise cycle')); | ||
} | ||
// Snapshot states | ||
@@ -569,0 +586,0 @@ |
@@ -8,101 +8,135 @@ /** @license MIT License (c) copyright 2010-2014 original author or authors */ | ||
var stackJumpSeparator = ' ... [from] ...'; | ||
var stackJumpSeparator = '... from ...'; | ||
var allHandledMsg = '[promises] All previously unhandled rejections have now been handled'; | ||
var unhandledRejectionsMsg = '[promises] Unhandled rejections: '; | ||
var warn, groupStart, groupEnd; | ||
groupStart = groupEnd = consoleGroupsNotAvailable; | ||
if(typeof console === 'undefined') { | ||
warn = consoleNotAvailable; | ||
} else { | ||
if(typeof console.warn === 'function' | ||
&& typeof console.dir === 'function') { | ||
warn = function(s) { | ||
console.warn(s); | ||
}; | ||
if(typeof console.groupCollapsed === 'function') { | ||
groupStart = function(s) { | ||
console.groupCollapsed(s); | ||
}; | ||
groupEnd = function() { | ||
console.groupEnd(); | ||
}; | ||
} | ||
} else { | ||
// IE8 has console.log and JSON, so we can make a | ||
// reasonably useful warn() from those. | ||
// Credit to webpro (https://github.com/webpro) for this idea | ||
if (typeof console.log ==='function' | ||
&& typeof JSON !== 'undefined') { | ||
warn = function (x) { | ||
console.log(typeof x === 'string' ? x : JSON.stringify(x)); | ||
}; | ||
} | ||
} | ||
} | ||
function ConsoleReporter(stackFilter) { | ||
this._stackFilter = stackFilter; | ||
this.stackFilter = stackFilter; | ||
this._previouslyReported = false; | ||
} | ||
ConsoleReporter.prototype._warn = warn; | ||
ConsoleReporter.prototype._groupStart = groupStart; | ||
ConsoleReporter.prototype._groupEnd = groupEnd; | ||
ConsoleReporter.prototype = initDefaultLogging(); | ||
ConsoleReporter.prototype.report = function(traces) { | ||
ConsoleReporter.prototype.log = function(traces) { | ||
var keys = Object.keys(traces); | ||
if(keys.length === 0) { | ||
this._warn(allHandledMsg); | ||
if(this._previouslyReported) { | ||
this._previouslyReported = false; | ||
this.warn(allHandledMsg); | ||
} | ||
return; | ||
} | ||
this._groupStart(unhandledRejectionsMsg + keys.length); | ||
this._previouslyReported = true; | ||
this.groupStart(unhandledRejectionsMsg + keys.length); | ||
try { | ||
this._formatTraces(traces, keys); | ||
this.formatTraces(traces, keys); | ||
} finally { | ||
this._groupEnd(); | ||
this.groupEnd(); | ||
} | ||
}; | ||
ConsoleReporter.prototype._joinLongTrace = function(stackFilter, trace) { | ||
return trace.reduce(function (longTrace, e, i) { | ||
var stack = e && e.stack; | ||
ConsoleReporter.prototype.formatTraces = function(traces, keys) { | ||
for(var i=0; i<keys.length; ++i) { | ||
var longTrace = this.createLongTrace(traces[keys[i]]); | ||
this.warn(join(longTrace) + '\n'); | ||
} | ||
}; | ||
ConsoleReporter.prototype.createLongTrace = function(trace) { | ||
var self = this; | ||
var first; | ||
var longTrace = []; | ||
var seen = {}; | ||
for(var i=0; i<trace.length; ++i) { | ||
var stack = self.getStack(trace[i]); | ||
if (stack) { | ||
stack = stack.split('\n').filter(function (frame) { | ||
return !(stackFilter.test(frame)); | ||
}); | ||
if(i === 0) { | ||
longTrace.push.apply(longTrace, stack); | ||
} else if (stack.length > 1) { | ||
stack[0] = stackJumpSeparator; | ||
longTrace.push.apply(longTrace, stack); | ||
stack = stack.split('\n'); | ||
first = stack[0]; | ||
stack = self.getFilteredFrames(seen, stack.slice(1)); | ||
if (stack.length > 0) { | ||
longTrace.push(i === 0 ? first : stackJumpSeparator); | ||
longTrace.push(join(stack)); | ||
} | ||
} else { | ||
longTrace.push(String(e)); | ||
longTrace.push(String(trace[i])); | ||
} | ||
return longTrace; | ||
} | ||
return longTrace; | ||
}; | ||
ConsoleReporter.prototype.getStack = function(e) { | ||
return e && e.stack; | ||
}; | ||
ConsoleReporter.prototype.getFilteredFrames = function(seen, stack) { | ||
var stackFilter = this.stackFilter; | ||
return stack.reduce(function (filtered, frame) { | ||
if (!(seen[frame] || stackFilter.test(frame))) { | ||
seen[frame] = true; | ||
filtered.push(frame); | ||
} | ||
return filtered; | ||
}, []); | ||
}; | ||
ConsoleReporter.prototype._formatTraces = function(traces, keys) { | ||
keys.forEach(function (key) { | ||
var trace = traces[key]; | ||
if (typeof trace === 'string') { | ||
this._warn(trace); | ||
return; | ||
// About 5-10x faster than String.prototype.join o_O | ||
function join(a) { | ||
var sep = false; | ||
var s = ''; | ||
for(var i=0; i< a.length; ++i) { | ||
if(sep) { | ||
s += '\n' + a[i]; | ||
} else { | ||
s+= a[i]; | ||
sep = true; | ||
} | ||
} | ||
return s; | ||
} | ||
var longTrace = this._joinLongTrace(this._stackFilter, trace); | ||
longTrace = traces[key] = longTrace.join('\n'); | ||
function initDefaultLogging() { | ||
var warn, groupStart, groupEnd; | ||
this._warn(longTrace); | ||
}, this); | ||
}; | ||
if(typeof console === 'undefined') { | ||
warn = consoleNotAvailable; | ||
} else { | ||
if(typeof console.warn === 'function' | ||
&& typeof console.dir === 'function') { | ||
warn = function(s) { | ||
console.warn(s); | ||
}; | ||
if(typeof console.groupCollapsed === 'function') { | ||
groupStart = function(s) { | ||
console.groupCollapsed(s); | ||
}; | ||
groupEnd = function() { | ||
console.groupEnd(); | ||
}; | ||
} | ||
} else { | ||
// IE8 has console.log and JSON, so we can make a | ||
// reasonably useful warn() from those. | ||
// Credit to webpro (https://github.com/webpro) for this idea | ||
if (typeof console.log ==='function' | ||
&& typeof JSON !== 'undefined') { | ||
warn = function (x) { | ||
console.log(typeof x === 'string' ? x : JSON.stringify(x)); | ||
}; | ||
} | ||
} | ||
} | ||
return { | ||
warn: warn, | ||
groupStart: groupStart || warn, | ||
groupEnd: groupEnd || consoleNotAvailable | ||
}; | ||
} | ||
function consoleNotAvailable() {} | ||
function consoleGroupsNotAvailable() {} | ||
@@ -109,0 +143,0 @@ return ConsoleReporter; |
@@ -6,4 +6,6 @@ /** @license MIT License (c) copyright 2010-2014 original author or authors */ | ||
(function(define) { 'use strict'; | ||
define(function() { | ||
define(function(require) { | ||
var setTimer = require('../lib/timer').set; | ||
function PromiseMonitor(reporter) { | ||
@@ -36,4 +38,3 @@ this.key = 0; | ||
if(typeof t !== 'undefined') { | ||
t = t.concat(trace); | ||
this.traces[key] = t; | ||
t.push(trace); | ||
this.logTraces(); | ||
@@ -52,3 +53,3 @@ } | ||
if(!this.traceTask) { | ||
this.traceTask = setTimeout(this._doLogTraces, this.logDelay); | ||
this.traceTask = setTimer(this._doLogTraces, this.logDelay); | ||
} | ||
@@ -59,3 +60,3 @@ }; | ||
this.traceTask = void 0; | ||
this._reporter.report(this.traces); | ||
this._reporter.log(this.traces); | ||
}; | ||
@@ -65,2 +66,2 @@ | ||
}); | ||
}(typeof define === 'function' && define.amd ? define : function(factory) { module.exports = factory(); })); | ||
}(typeof define === 'function' && define.amd ? define : function(factory) { module.exports = factory(require); })); |
{ | ||
"name": "when", | ||
"version": "3.0.0", | ||
"version": "3.0.1", | ||
"description": "A lightweight Promises/A+ and when() implementation, plus other async goodies.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -8,3 +8,3 @@ /** @license MIT License (c) copyright 2010-2014 original author or authors */ | ||
* @author John Hann | ||
* @version 3.0.0 | ||
* @version 3.0.1 | ||
*/ | ||
@@ -11,0 +11,0 @@ (function(define) { 'use strict'; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
147853
3652
0