Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

polyfill() does not polyfill Promise.prototype.finally() if the environment already has a Promise implementation. #330

Open
shirakaba opened this issue Mar 13, 2018 · 6 comments

Comments

@shirakaba
Copy link

shirakaba commented Mar 13, 2018

In polyfill.js, observe line 30: https://github.com/stefanpenner/es6-promise/blob/master/lib/es6-promise/polyfill.js#L30

As I understand it, if a Promise implementation is found on the global object, then the polyfill will use the global object's Promise implementation as-is, not augmenting it with the stage 4 ES9/ES2018 feature proposal provided in this library, Promise.prototype.finally().

Is this intended behaviour, or a bug? Surely if I have polyfilled es6-promise, I should be getting at least all the advertised features of es6-promise?

@YurySolovyov
Copy link

Do you know if it works in -auto variant?

@shirakaba
Copy link
Author

@YurySolovyov require('es6-promise/auto') is just an alias for require('es6-promise').polyfill(), so this issue affects both usages.

@YurySolovyov
Copy link

Thanks, good to know

@radarfox
Copy link

Following browser only polyfill setup works for browsers:

  • without Promise
  • with Promise and without finally
  • with both Promise and finally

It also polyfills promises used in Fetch API and other promise based APIs.

import Promise from 'es6-promise';
if (!('Promise' in window)) {
  window.Promise = Promise;
} else if (!('finally' in window.Promise.prototype)) {
  window.Promise.prototype.finally = Promise.prototype.finally;
}

@gitgrimbo
Copy link

gitgrimbo commented Sep 27, 2018

Does the finally method even exist on the ES6Promise object?

In IE 11, I see the following if I include https://cdnjs.cloudflare.com/ajax/libs/es6-promise/4.1.1/es6-promise.min.js in a script tag.

new ES6Promise(function(){}).finally === undefined

If I include https://cdn.jsdelivr.net/bluebird/latest/bluebird.core.min.js I see:

new Promise(function(){}).finally === function(t){return this._passThrough(t,0,l,l)}

So for my application at least, using bluebird seemed to provide a Promise implementation with a finally method.

And the bluebird approach also provides the finally method when I test on MS Edge.

@Montana
Copy link

Montana commented Apr 5, 2019

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants