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

promise-polyfill

Package Overview
Dependencies
Maintainers
1
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

promise-polyfill - npm Package Compare versions

Comparing version 8.0.0 to 8.1.0

2

CHANGELOG.md

@@ -6,3 +6,3 @@ # Changelog

* Polyfill default promise with `finally` if it doesn't exist if you use polyfill.js
* If using `require` with webpack 2+, you not need to do
* If using `require` with webpack 2+, you now need to do

@@ -9,0 +9,0 @@ ```js

@@ -7,3 +7,6 @@ (function (global, factory) {

var promiseFinally = function(callback) {
/**
* @this {Promise}
*/
function finallyConstructor(callback) {
var constructor = this.constructor;

@@ -22,3 +25,3 @@ return this.then(

);
};
}

@@ -38,2 +41,6 @@ // Store setTimeout reference so promise-polyfill will be unaffected by

/**
* @constructor
* @param {Function} fn
*/
function Promise(fn) {

@@ -43,5 +50,9 @@ if (!(this instanceof Promise))

if (typeof fn !== 'function') throw new TypeError('not a function');
/** @type {!number} */
this._state = 0;
/** @type {!boolean} */
this._handled = false;
/** @type {Promise|undefined} */
this._value = undefined;
/** @type {!Array<!Function>} */
this._deferreds = [];

@@ -127,2 +138,5 @@

/**
* @constructor
*/
function Handler(onFulfilled, onRejected, promise) {

@@ -167,2 +181,3 @@ this.onFulfilled = typeof onFulfilled === 'function' ? onFulfilled : null;

Promise.prototype.then = function(onFulfilled, onRejected) {
// @ts-ignore
var prom = new this.constructor(noop);

@@ -174,3 +189,3 @@

Promise.prototype['finally'] = promiseFinally;
Promise.prototype['finally'] = finallyConstructor;

@@ -255,2 +270,3 @@ Promise.all = function(arr) {

/** @suppress {undefinedVars} */
var globalNS = (function() {

@@ -272,8 +288,8 @@ // the only reliable means to get the global object is

if (!globalNS.Promise) {
globalNS.Promise = Promise;
if (!('Promise' in globalNS)) {
globalNS['Promise'] = Promise;
} else if (!globalNS.Promise.prototype['finally']) {
globalNS.Promise.prototype['finally'] = promiseFinally;
globalNS.Promise.prototype['finally'] = finallyConstructor;
}
})));

@@ -1,1 +0,1 @@

!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n():"function"==typeof define&&define.amd?define(n):n()}(0,function(){"use strict";function e(){}function n(e){if(!(this instanceof n))throw new TypeError("Promises must be constructed via new");if("function"!=typeof e)throw new TypeError("not a function");this._state=0,this._handled=!1,this._value=undefined,this._deferreds=[],f(e,this)}function t(e,t){for(;3===e._state;)e=e._value;0!==e._state?(e._handled=!0,n._immediateFn(function(){var n=1===e._state?t.onFulfilled:t.onRejected;if(null!==n){var i;try{i=n(e._value)}catch(f){return void r(t.promise,f)}o(t.promise,i)}else(1===e._state?o:r)(t.promise,e._value)})):e._deferreds.push(t)}function o(e,t){try{if(t===e)throw new TypeError("A promise cannot be resolved with itself.");if(t&&("object"==typeof t||"function"==typeof t)){var o=t.then;if(t instanceof n)return e._state=3,e._value=t,void i(e);if("function"==typeof o)return void f(function(e,n){return function(){e.apply(n,arguments)}}(o,t),e)}e._state=1,e._value=t,i(e)}catch(u){r(e,u)}}function r(e,n){e._state=2,e._value=n,i(e)}function i(e){2===e._state&&0===e._deferreds.length&&n._immediateFn(function(){e._handled||n._unhandledRejectionFn(e._value)});for(var o=0,r=e._deferreds.length;r>o;o++)t(e,e._deferreds[o]);e._deferreds=null}function f(e,n){var t=!1;try{e(function(e){t||(t=!0,o(n,e))},function(e){t||(t=!0,r(n,e))})}catch(i){if(t)return;t=!0,r(n,i)}}var u=function(e){var n=this.constructor;return this.then(function(t){return n.resolve(e()).then(function(){return t})},function(t){return n.resolve(e()).then(function(){return n.reject(t)})})},c=setTimeout;n.prototype["catch"]=function(e){return this.then(null,e)},n.prototype.then=function(n,o){var r=new this.constructor(e);return t(this,new function(e,n,t){this.onFulfilled="function"==typeof e?e:null,this.onRejected="function"==typeof n?n:null,this.promise=t}(n,o,r)),r},n.prototype["finally"]=u,n.all=function(e){return new n(function(n,t){function o(e,f){try{if(f&&("object"==typeof f||"function"==typeof f)){var u=f.then;if("function"==typeof u)return void u.call(f,function(n){o(e,n)},t)}r[e]=f,0==--i&&n(r)}catch(c){t(c)}}if(!e||"undefined"==typeof e.length)throw new TypeError("Promise.all accepts an array");var r=Array.prototype.slice.call(e);if(0===r.length)return n([]);for(var i=r.length,f=0;r.length>f;f++)o(f,r[f])})},n.resolve=function(e){return e&&"object"==typeof e&&e.constructor===n?e:new n(function(n){n(e)})},n.reject=function(e){return new n(function(n,t){t(e)})},n.race=function(e){return new n(function(n,t){for(var o=0,r=e.length;r>o;o++)e[o].then(n,t)})},n._immediateFn="function"==typeof setImmediate&&function(e){setImmediate(e)}||function(e){c(e,0)},n._unhandledRejectionFn=function(e){void 0!==console&&console&&console.warn("Possible Unhandled Promise Rejection:",e)};var l=function(){if("undefined"!=typeof self)return self;if("undefined"!=typeof window)return window;if("undefined"!=typeof global)return global;throw Error("unable to locate global object")}();l.Promise?l.Promise.prototype["finally"]||(l.Promise.prototype["finally"]=u):l.Promise=n});
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n():"function"==typeof define&&define.amd?define(n):n()}(0,function(){"use strict";function e(e){var n=this.constructor;return this.then(function(t){return n.resolve(e()).then(function(){return t})},function(t){return n.resolve(e()).then(function(){return n.reject(t)})})}function n(){}function t(e){if(!(this instanceof t))throw new TypeError("Promises must be constructed via new");if("function"!=typeof e)throw new TypeError("not a function");this._state=0,this._handled=!1,this._value=undefined,this._deferreds=[],u(e,this)}function o(e,n){for(;3===e._state;)e=e._value;0!==e._state?(e._handled=!0,t._immediateFn(function(){var t=1===e._state?n.onFulfilled:n.onRejected;if(null!==t){var o;try{o=t(e._value)}catch(f){return void i(n.promise,f)}r(n.promise,o)}else(1===e._state?r:i)(n.promise,e._value)})):e._deferreds.push(n)}function r(e,n){try{if(n===e)throw new TypeError("A promise cannot be resolved with itself.");if(n&&("object"==typeof n||"function"==typeof n)){var o=n.then;if(n instanceof t)return e._state=3,e._value=n,void f(e);if("function"==typeof o)return void u(function(e,n){return function(){e.apply(n,arguments)}}(o,n),e)}e._state=1,e._value=n,f(e)}catch(r){i(e,r)}}function i(e,n){e._state=2,e._value=n,f(e)}function f(e){2===e._state&&0===e._deferreds.length&&t._immediateFn(function(){e._handled||t._unhandledRejectionFn(e._value)});for(var n=0,r=e._deferreds.length;r>n;n++)o(e,e._deferreds[n]);e._deferreds=null}function u(e,n){var t=!1;try{e(function(e){t||(t=!0,r(n,e))},function(e){t||(t=!0,i(n,e))})}catch(o){if(t)return;t=!0,i(n,o)}}var c=setTimeout;t.prototype["catch"]=function(e){return this.then(null,e)},t.prototype.then=function(e,t){var r=new this.constructor(n);return o(this,new function(e,n,t){this.onFulfilled="function"==typeof e?e:null,this.onRejected="function"==typeof n?n:null,this.promise=t}(e,t,r)),r},t.prototype["finally"]=e,t.all=function(e){return new t(function(n,t){function o(e,f){try{if(f&&("object"==typeof f||"function"==typeof f)){var u=f.then;if("function"==typeof u)return void u.call(f,function(n){o(e,n)},t)}r[e]=f,0==--i&&n(r)}catch(c){t(c)}}if(!e||"undefined"==typeof e.length)throw new TypeError("Promise.all accepts an array");var r=Array.prototype.slice.call(e);if(0===r.length)return n([]);for(var i=r.length,f=0;r.length>f;f++)o(f,r[f])})},t.resolve=function(e){return e&&"object"==typeof e&&e.constructor===t?e:new t(function(n){n(e)})},t.reject=function(e){return new t(function(n,t){t(e)})},t.race=function(e){return new t(function(n,t){for(var o=0,r=e.length;r>o;o++)e[o].then(n,t)})},t._immediateFn="function"==typeof setImmediate&&function(e){setImmediate(e)}||function(e){c(e,0)},t._unhandledRejectionFn=function(e){void 0!==console&&console&&console.warn("Possible Unhandled Promise Rejection:",e)};var l=function(){if("undefined"!=typeof self)return self;if("undefined"!=typeof window)return window;if("undefined"!=typeof global)return global;throw Error("unable to locate global object")}();"Promise"in l?l.Promise.prototype["finally"]||(l.Promise.prototype["finally"]=e):l.Promise=t});
'use strict';
var promiseFinally = function(callback) {
/**
* @this {Promise}
*/
function finallyConstructor(callback) {
var constructor = this.constructor;

@@ -17,3 +20,3 @@ return this.then(

);
};
}

@@ -33,2 +36,6 @@ // Store setTimeout reference so promise-polyfill will be unaffected by

/**
* @constructor
* @param {Function} fn
*/
function Promise(fn) {

@@ -38,5 +45,9 @@ if (!(this instanceof Promise))

if (typeof fn !== 'function') throw new TypeError('not a function');
/** @type {!number} */
this._state = 0;
/** @type {!boolean} */
this._handled = false;
/** @type {Promise|undefined} */
this._value = undefined;
/** @type {!Array<!Function>} */
this._deferreds = [];

@@ -122,2 +133,5 @@

/**
* @constructor
*/
function Handler(onFulfilled, onRejected, promise) {

@@ -162,2 +176,3 @@ this.onFulfilled = typeof onFulfilled === 'function' ? onFulfilled : null;

Promise.prototype.then = function(onFulfilled, onRejected) {
// @ts-ignore
var prom = new this.constructor(noop);

@@ -169,3 +184,3 @@

Promise.prototype['finally'] = promiseFinally;
Promise.prototype['finally'] = finallyConstructor;

@@ -172,0 +187,0 @@ Promise.all = function(arr) {

'use strict';
var promiseFinally = function(callback) {
/**
* @this {Promise}
*/
function finallyConstructor(callback) {
var constructor = this.constructor;

@@ -17,3 +20,3 @@ return this.then(

);
};
}

@@ -33,2 +36,6 @@ // Store setTimeout reference so promise-polyfill will be unaffected by

/**
* @constructor
* @param {Function} fn
*/
function Promise(fn) {

@@ -38,5 +45,9 @@ if (!(this instanceof Promise))

if (typeof fn !== 'function') throw new TypeError('not a function');
/** @type {!number} */
this._state = 0;
/** @type {!boolean} */
this._handled = false;
/** @type {Promise|undefined} */
this._value = undefined;
/** @type {!Array<!Function>} */
this._deferreds = [];

@@ -122,2 +133,5 @@

/**
* @constructor
*/
function Handler(onFulfilled, onRejected, promise) {

@@ -162,2 +176,3 @@ this.onFulfilled = typeof onFulfilled === 'function' ? onFulfilled : null;

Promise.prototype.then = function(onFulfilled, onRejected) {
// @ts-ignore
var prom = new this.constructor(noop);

@@ -169,3 +184,3 @@

Promise.prototype['finally'] = promiseFinally;
Promise.prototype['finally'] = finallyConstructor;

@@ -250,2 +265,3 @@ Promise.all = function(arr) {

/** @suppress {undefinedVars} */
var globalNS = (function() {

@@ -267,6 +283,6 @@ // the only reliable means to get the global object is

if (!globalNS.Promise) {
globalNS.Promise = Promise;
if (!('Promise' in globalNS)) {
globalNS['Promise'] = Promise;
} else if (!globalNS.Promise.prototype['finally']) {
globalNS.Promise.prototype['finally'] = promiseFinally;
globalNS.Promise.prototype['finally'] = finallyConstructor;
}
{
"name": "promise-polyfill",
"version": "8.0.0",
"version": "8.1.0",
"description": "Lightweight promise polyfill. A+ compliant",

@@ -17,3 +17,6 @@ "main": "lib/index.js",

"pretest": "npm run build:cjs",
"test": "eslint src && mocha && karma start --single-run",
"closure": "google-closure-compiler --js=src/*.js --checks_only --module_resolution=node --compilation_level=ADVANCED",
"typescript": "tsc --checkJS --allowJS --noEmit src/index.js",
"lint": "eslint src && npm run closure && npm run typescript",
"test": "npm run lint && mocha && karma start --single-run",
"prebuild": "rimraf lib dist",

@@ -41,2 +44,3 @@ "build": "run-p build:**",

"eslint": "^4.11.0",
"google-closure-compiler": "^20180610.0.1",
"husky": "^0.14.3",

@@ -55,3 +59,4 @@ "karma": "^0.13.19",

"rollup-plugin-uglify": "^2.0.1",
"sinon": "^1.17.2"
"sinon": "^1.17.2",
"typescript": "^2.9.2"
},

@@ -58,0 +63,0 @@ "keywords": [

@@ -113,2 +113,4 @@ # Promise Polyfill

-**NOTE: This only works on promise-polyfill Promises. Native Promises do not support this function**
```js

@@ -115,0 +117,0 @@ Promise._unhandledRejectionFn = <your reject error handler>;

@@ -1,2 +0,5 @@

export default function(callback) {
/**
* @this {Promise}
*/
function finallyConstructor(callback) {
var constructor = this.constructor;

@@ -16,1 +19,3 @@ return this.then(

}
export default finallyConstructor;

@@ -16,2 +16,6 @@ import promiseFinally from './finally';

/**
* @constructor
* @param {Function} fn
*/
function Promise(fn) {

@@ -21,5 +25,9 @@ if (!(this instanceof Promise))

if (typeof fn !== 'function') throw new TypeError('not a function');
/** @type {!number} */
this._state = 0;
/** @type {!boolean} */
this._handled = false;
/** @type {Promise|undefined} */
this._value = undefined;
/** @type {!Array<!Function>} */
this._deferreds = [];

@@ -105,2 +113,5 @@

/**
* @constructor
*/
function Handler(onFulfilled, onRejected, promise) {

@@ -145,2 +156,3 @@ this.onFulfilled = typeof onFulfilled === 'function' ? onFulfilled : null;

Promise.prototype.then = function(onFulfilled, onRejected) {
// @ts-ignore
var prom = new this.constructor(noop);

@@ -147,0 +159,0 @@

import Promise from './index';
import promiseFinally from './finally';
/** @suppress {undefinedVars} */
var globalNS = (function() {

@@ -20,6 +21,6 @@ // the only reliable means to get the global object is

if (!globalNS.Promise) {
globalNS.Promise = Promise;
if (!('Promise' in globalNS)) {
globalNS['Promise'] = Promise;
} else if (!globalNS.Promise.prototype['finally']) {
globalNS.Promise.prototype['finally'] = promiseFinally;
}
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