Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

when

Package Overview
Dependencies
Maintainers
1
Versions
63
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

when - npm Package Compare versions

Comparing version 3.2.2 to 3.2.3

243

es6-shim/Promise.js

@@ -181,31 +181,64 @@ !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 async = require('../async');
var timer = require('../timer');
return function unhandledRejection(Promise) {
var logError = (function() {
if(typeof console !== 'undefined') {
if(typeof console.error !== 'undefined') {
return function(e) {
console.error(e);
};
}
var logError = noop;
var logInfo = noop;
return function(e) {
console.log(e);
};
}
if(typeof console !== 'undefined') {
logError = typeof console.error !== 'undefined'
? function (e) { console.error(e); }
: function (e) { console.log(e); };
return noop;
}());
logInfo = typeof console.info !== 'undefined'
? function (e) { console.info(e); }
: function (e) { console.log(e); };
}
Promise.onPotentiallyUnhandledRejection = function(rejection) {
logError('Potentially unhandled rejection ' + formatError(rejection.value));
enqueue(report, rejection);
};
Promise.onPotentiallyUnhandledRejectionHandled = function(rejection) {
enqueue(unreport, rejection);
};
Promise.onFatalRejection = function(rejection) {
async(function() {
throw rejection.value;
});
enqueue(throwit, rejection.value);
};
var tasks = [];
var reported = [];
var running = false;
function report(r) {
if(!r.handled) {
reported.push(r);
logError('Potentially unhandled rejection [' + r.id + '] ' + formatError(r.value));
}
}
function unreport(r) {
var i = reported.indexOf(r);
if(i >= 0) {
reported.splice(i, 1);
logInfo('Handled previous rejection [' + r.id + '] ' + formatObject(r.value));
}
}
function enqueue(f, x) {
tasks.push(f, x);
if(!running) {
running = true;
running = timer.set(flush, 0);
}
}
function flush() {
running = false;
while(tasks.length > 0) {
tasks.shift()(tasks.shift());
}
}
return Promise;

@@ -215,15 +248,14 @@ };

function formatError(e) {
var s;
if(typeof e === 'object' && e.stack) {
s = e.stack;
} else {
s = String(e);
if(s === '[object Object]' && typeof JSON !== 'undefined') {
s = tryStringify(e, s);
}
}
var s = typeof e === 'object' && e.stack ? e.stack : formatObject(e);
return e instanceof Error ? s : s + ' (WARNING: non-Error used)';
}
function formatObject(o) {
var s = String(o);
if(s === '[object Object]' && typeof JSON !== 'undefined') {
s = tryStringify(o, s);
}
return s;
}
function tryStringify(e, defaultValue) {

@@ -238,2 +270,6 @@ try {

function throwit(e) {
throw e;
}
function noop() {}

@@ -244,3 +280,3 @@

},{"../async":4}],6:[function(require,module,exports){
},{"../timer":8}],6:[function(require,module,exports){
/** @license MIT License (c) copyright 2010-2014 original author or authors */

@@ -272,4 +308,2 @@ /** @author Brian Cavalier */

this._handler = resolver === Handler ? handler : init(resolver);
// this._handler = arguments.length === 0
// ? foreverPendingHandler : init(resolver);
}

@@ -334,3 +368,3 @@

function resolve(x) {
return x instanceof Promise ? x
return isPromise(x) ? x
: new Promise(Handler, new AsyncHandler(getHandler(x)));

@@ -380,3 +414,3 @@ }

if (typeof onFulfilled !== 'function' && parent.join().state > 0) {
if (typeof onFulfilled !== 'function' && parent.join().state() > 0) {
// Short circuit: value will not change, simply share handler

@@ -469,3 +503,3 @@ return new Promise(Handler, parent);

var i, h, x;
var i, h, x, s;
for (i = 0; i < promises.length; ++i) {

@@ -480,13 +514,14 @@ x = promises[i];

if (maybeThenable(x)) {
h = x instanceof Promise
h = isPromise(x)
? x._handler.join()
: getHandlerUntrusted(x);
if (h.state === 0) {
s = h.state();
if (s === 0) {
resolveOne(resolver, results, h, i);
} else if (h.state > 0) {
} else if (s > 0) {
results[i] = h.value;
--pending;
} else {
h.catchError(resolver.reject, resolver);
resolver.become(h);
break;

@@ -502,3 +537,3 @@ }

if(pending === 0) {
resolver.resolve(results);
resolver.become(new FulfilledHandler(results));
}

@@ -511,3 +546,3 @@

if(--pending === 0) {
this.resolve(results);
this.become(new FulfilledHandler(results));
}

@@ -559,3 +594,3 @@ }, resolver);

function getHandler(x) {
if(x instanceof Promise) {
if(isPromise(x)) {
return x._handler.join();

@@ -566,2 +601,6 @@ }

function isPromise(x) {
return x instanceof Promise;
}
/**

@@ -588,5 +627,3 @@ * Get a handler for potentially untrusted thenable x

*/
function Handler() {
this.state = 0;
}
function Handler() {}

@@ -604,2 +641,8 @@ Handler.prototype.when

Handler.prototype._state = 0;
Handler.prototype.state = function() {
return this._state;
};
/**

@@ -658,3 +701,2 @@ * Recursively collapse handler chain to find the handler

this.resolved = false;
this.state = 0;
}

@@ -664,2 +706,4 @@

DeferredHandler.prototype._state = 0;
DeferredHandler.prototype.inspect = function() {

@@ -757,3 +801,2 @@ return this.resolved ? this.join().inspect() : toPendingState();

this.handler = handler;
this.state = 0;
}

@@ -825,5 +868,3 @@

DeferredHandler.call(this);
this.assimilated = false;
this.untrustedThen = then;
this.thenable = thenable;
tasks.enqueue(new AssimilateTask(then, thenable, this));
}

@@ -833,26 +874,2 @@

ThenableHandler.prototype.when = function(continuation) {
if(!this.assimilated) {
this.assimilated = true;
assimilate(this);
}
DeferredHandler.prototype.when.call(this, continuation);
};
function assimilate(h) {
tryAssimilate(h.untrustedThen, h.thenable, _resolve, _reject, _notify);
function _resolve(x) { h.resolve(x); }
function _reject(x) { h.reject(x); }
function _notify(x) { h.notify(x); }
}
function tryAssimilate(then, thenable, resolve, reject, notify) {
try {
then.call(thenable, resolve, reject, notify);
} catch (e) {
reject(e);
}
}
/**

@@ -866,5 +883,3 @@ * Handler for a fulfilled promise

Promise.createContext(this);
this.value = x;
this.state = 1;
}

@@ -874,2 +889,4 @@

FulfilledHandler.prototype._state = 1;
FulfilledHandler.prototype.inspect = function() {

@@ -893,2 +910,3 @@ return { state: 'fulfilled', value: this.value };

var id = 0;
/**

@@ -903,5 +921,6 @@ * Handler for a rejected promise

this.id = ++id;
this.value = x;
this.state = -1; // -1: rejected, -2: rejected and reported
this.handled = false;
this.reported = false;

@@ -913,2 +932,4 @@ this._report();

RejectedHandler.prototype._state = -1;
RejectedHandler.prototype.inspect = function() {

@@ -949,3 +970,3 @@ return { state: 'rejected', reason: this.value };

if(!rejection.handled) {
rejection.state = -2;
rejection.reported = true;
Promise.onPotentiallyUnhandledRejection(rejection, context);

@@ -956,3 +977,3 @@ }

function reportHandled(rejection) {
if(rejection.state === -2) {
if(rejection.reported) {
Promise.onPotentiallyUnhandledRejectionHandled(rejection);

@@ -1041,2 +1062,33 @@ }

/**
* Assimilate a thenable, sending it's value to resolver
* @private
* @param {function} then
* @param {object|function} thenable
* @param {object} resolver
* @constructor
*/
function AssimilateTask(then, thenable, resolver) {
this._then = then;
this.thenable = thenable;
this.resolver = resolver;
}
AssimilateTask.prototype.run = function() {
var h = this.resolver;
tryAssimilate(this._then, this.thenable, _resolve, _reject, _notify);
function _resolve(x) { h.resolve(x); }
function _reject(x) { h.reject(x); }
function _notify(x) { h.notify(x); }
};
function tryAssimilate(then, thenable, resolve, reject, notify) {
try {
then.call(thenable, resolve, reject, notify);
} catch (e) {
reject(e);
}
}
// Other helpers

@@ -1160,2 +1212,4 @@

this._running = false;
q = this._afterQueue;

@@ -1165,4 +1219,2 @@ while(q.length > 0) {

}
this._running = false;
};

@@ -1175,5 +1227,34 @@

},{"./Queue":3}]},{},[1])
},{"./Queue":3}],8:[function(require,module,exports){
/** @license MIT License (c) copyright 2010-2014 original author or authors */
/** @author Brian Cavalier */
/** @author John Hann */
(function(define) { 'use strict';
define(function(require) {
/*global setTimeout,clearTimeout*/
var cjsRequire, vertx, setTimer, clearTimer;
cjsRequire = require;
try {
vertx = cjsRequire('vertx');
setTimer = function (f, ms) { return vertx.setTimer(ms, f); };
clearTimer = vertx.cancelTimer;
} catch (e) {
setTimer = function(f, ms) { return setTimeout(f, ms); };
clearTimer = function(t) { return clearTimeout(t); };
}
return {
set: setTimer,
clear: clearTimer
};
});
}(typeof define === 'function' && define.amd ? define : function(factory) { module.exports = factory(require); }));
},{}]},{},[1])
(1)
});
;

@@ -31,7 +31,6 @@ /** @license MIT License (c) copyright 2011-2013 original author or authors */

return function() {
var self = this;
var args = slice.call(arguments);
return when(condition(), function(exit) {
return when(f.apply(self, args))['finally'](exit);
return when(condition()).withThis(this).then(function(exit) {
return when(f.apply(this, args))['finally'](exit);
});

@@ -62,11 +61,11 @@ };

count += 1;
function exit() {
count = Math.max(count - 1, 0);
if(waiting.length > 0) {
waiting.shift()(exit);
}
}
});
};
function exit() {
count = Math.max(count - 1, 0);
if(waiting.length > 0) {
waiting.shift()(exit);
}
}
}

@@ -73,0 +72,0 @@

@@ -8,31 +8,64 @@ /** @license MIT License (c) copyright 2010-2014 original author or authors */

var async = require('../async');
var timer = require('../timer');
return function unhandledRejection(Promise) {
var logError = (function() {
if(typeof console !== 'undefined') {
if(typeof console.error !== 'undefined') {
return function(e) {
console.error(e);
};
}
var logError = noop;
var logInfo = noop;
return function(e) {
console.log(e);
};
}
if(typeof console !== 'undefined') {
logError = typeof console.error !== 'undefined'
? function (e) { console.error(e); }
: function (e) { console.log(e); };
return noop;
}());
logInfo = typeof console.info !== 'undefined'
? function (e) { console.info(e); }
: function (e) { console.log(e); };
}
Promise.onPotentiallyUnhandledRejection = function(rejection) {
logError('Potentially unhandled rejection ' + formatError(rejection.value));
enqueue(report, rejection);
};
Promise.onPotentiallyUnhandledRejectionHandled = function(rejection) {
enqueue(unreport, rejection);
};
Promise.onFatalRejection = function(rejection) {
async(function() {
throw rejection.value;
});
enqueue(throwit, rejection.value);
};
var tasks = [];
var reported = [];
var running = false;
function report(r) {
if(!r.handled) {
reported.push(r);
logError('Potentially unhandled rejection [' + r.id + '] ' + formatError(r.value));
}
}
function unreport(r) {
var i = reported.indexOf(r);
if(i >= 0) {
reported.splice(i, 1);
logInfo('Handled previous rejection [' + r.id + '] ' + formatObject(r.value));
}
}
function enqueue(f, x) {
tasks.push(f, x);
if(!running) {
running = true;
running = timer.set(flush, 0);
}
}
function flush() {
running = false;
while(tasks.length > 0) {
tasks.shift()(tasks.shift());
}
}
return Promise;

@@ -42,15 +75,14 @@ };

function formatError(e) {
var s;
if(typeof e === 'object' && e.stack) {
s = e.stack;
} else {
s = String(e);
if(s === '[object Object]' && typeof JSON !== 'undefined') {
s = tryStringify(e, s);
}
}
var s = typeof e === 'object' && e.stack ? e.stack : formatObject(e);
return e instanceof Error ? s : s + ' (WARNING: non-Error used)';
}
function formatObject(o) {
var s = String(o);
if(s === '[object Object]' && typeof JSON !== 'undefined') {
s = tryStringify(o, s);
}
return s;
}
function tryStringify(e, defaultValue) {

@@ -65,2 +97,6 @@ try {

function throwit(e) {
throw e;
}
function noop() {}

@@ -67,0 +103,0 @@

@@ -27,4 +27,2 @@ /** @license MIT License (c) copyright 2010-2014 original author or authors */

this._handler = resolver === Handler ? handler : init(resolver);
// this._handler = arguments.length === 0
// ? foreverPendingHandler : init(resolver);
}

@@ -89,3 +87,3 @@

function resolve(x) {
return x instanceof Promise ? x
return isPromise(x) ? x
: new Promise(Handler, new AsyncHandler(getHandler(x)));

@@ -135,3 +133,3 @@ }

if (typeof onFulfilled !== 'function' && parent.join().state > 0) {
if (typeof onFulfilled !== 'function' && parent.join().state() > 0) {
// Short circuit: value will not change, simply share handler

@@ -224,3 +222,3 @@ return new Promise(Handler, parent);

var i, h, x;
var i, h, x, s;
for (i = 0; i < promises.length; ++i) {

@@ -235,13 +233,14 @@ x = promises[i];

if (maybeThenable(x)) {
h = x instanceof Promise
h = isPromise(x)
? x._handler.join()
: getHandlerUntrusted(x);
if (h.state === 0) {
s = h.state();
if (s === 0) {
resolveOne(resolver, results, h, i);
} else if (h.state > 0) {
} else if (s > 0) {
results[i] = h.value;
--pending;
} else {
h.catchError(resolver.reject, resolver);
resolver.become(h);
break;

@@ -257,3 +256,3 @@ }

if(pending === 0) {
resolver.resolve(results);
resolver.become(new FulfilledHandler(results));
}

@@ -266,3 +265,3 @@

if(--pending === 0) {
this.resolve(results);
this.become(new FulfilledHandler(results));
}

@@ -314,3 +313,3 @@ }, resolver);

function getHandler(x) {
if(x instanceof Promise) {
if(isPromise(x)) {
return x._handler.join();

@@ -321,2 +320,6 @@ }

function isPromise(x) {
return x instanceof Promise;
}
/**

@@ -343,5 +346,3 @@ * Get a handler for potentially untrusted thenable x

*/
function Handler() {
this.state = 0;
}
function Handler() {}

@@ -359,2 +360,8 @@ Handler.prototype.when

Handler.prototype._state = 0;
Handler.prototype.state = function() {
return this._state;
};
/**

@@ -413,3 +420,2 @@ * Recursively collapse handler chain to find the handler

this.resolved = false;
this.state = 0;
}

@@ -419,2 +425,4 @@

DeferredHandler.prototype._state = 0;
DeferredHandler.prototype.inspect = function() {

@@ -512,3 +520,2 @@ return this.resolved ? this.join().inspect() : toPendingState();

this.handler = handler;
this.state = 0;
}

@@ -580,5 +587,3 @@

DeferredHandler.call(this);
this.assimilated = false;
this.untrustedThen = then;
this.thenable = thenable;
tasks.enqueue(new AssimilateTask(then, thenable, this));
}

@@ -588,26 +593,2 @@

ThenableHandler.prototype.when = function(continuation) {
if(!this.assimilated) {
this.assimilated = true;
assimilate(this);
}
DeferredHandler.prototype.when.call(this, continuation);
};
function assimilate(h) {
tryAssimilate(h.untrustedThen, h.thenable, _resolve, _reject, _notify);
function _resolve(x) { h.resolve(x); }
function _reject(x) { h.reject(x); }
function _notify(x) { h.notify(x); }
}
function tryAssimilate(then, thenable, resolve, reject, notify) {
try {
then.call(thenable, resolve, reject, notify);
} catch (e) {
reject(e);
}
}
/**

@@ -621,5 +602,3 @@ * Handler for a fulfilled promise

Promise.createContext(this);
this.value = x;
this.state = 1;
}

@@ -629,2 +608,4 @@

FulfilledHandler.prototype._state = 1;
FulfilledHandler.prototype.inspect = function() {

@@ -648,2 +629,3 @@ return { state: 'fulfilled', value: this.value };

var id = 0;
/**

@@ -658,5 +640,6 @@ * Handler for a rejected promise

this.id = ++id;
this.value = x;
this.state = -1; // -1: rejected, -2: rejected and reported
this.handled = false;
this.reported = false;

@@ -668,2 +651,4 @@ this._report();

RejectedHandler.prototype._state = -1;
RejectedHandler.prototype.inspect = function() {

@@ -704,3 +689,3 @@ return { state: 'rejected', reason: this.value };

if(!rejection.handled) {
rejection.state = -2;
rejection.reported = true;
Promise.onPotentiallyUnhandledRejection(rejection, context);

@@ -711,3 +696,3 @@ }

function reportHandled(rejection) {
if(rejection.state === -2) {
if(rejection.reported) {
Promise.onPotentiallyUnhandledRejectionHandled(rejection);

@@ -796,2 +781,33 @@ }

/**
* Assimilate a thenable, sending it's value to resolver
* @private
* @param {function} then
* @param {object|function} thenable
* @param {object} resolver
* @constructor
*/
function AssimilateTask(then, thenable, resolver) {
this._then = then;
this.thenable = thenable;
this.resolver = resolver;
}
AssimilateTask.prototype.run = function() {
var h = this.resolver;
tryAssimilate(this._then, this.thenable, _resolve, _reject, _notify);
function _resolve(x) { h.resolve(x); }
function _reject(x) { h.reject(x); }
function _notify(x) { h.notify(x); }
};
function tryAssimilate(then, thenable, resolve, reject, notify) {
try {
then.call(thenable, resolve, reject, notify);
} catch (e) {
reject(e);
}
}
// Other helpers

@@ -798,0 +814,0 @@

@@ -59,2 +59,4 @@ /** @license MIT License (c) copyright 2010-2014 original author or authors */

this._running = false;
q = this._afterQueue;

@@ -64,4 +66,2 @@ while(q.length > 0) {

}
this._running = false;
};

@@ -68,0 +68,0 @@

{
"name": "when",
"version": "3.2.2",
"version": "3.2.3",
"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.2.2
* @version 3.2.3
*/

@@ -11,0 +11,0 @@ (function(define) { 'use strict';

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc