polyfill() does not polyfill Promise.prototype.finally() if the environment already has a Promise implementation.
shirakaba opened this issue · comments
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
?
Do you know if it works in -auto
variant?
@YurySolovyov require('es6-promise/auto')
is just an alias for require('es6-promise').polyfill()
, so this issue affects both usages.
Thanks, good to know
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;
}
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.
Thank you!