-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Promise.prototype.finally polyfill not applying to async functions #579
Comments
It's a known issue, but it's deeper than just missed Edge does not pass In The best solution for correct work here - add a transform-wrapper to Babel for environments which do not support async function () { /* ... */ }
// =>
function () {
return Promise.resolve(async function () { /* ... */ }.apply(this, arguments));
} |
… `Promise`, #579 added `.finally` and patched `.then` to / on native `Promise` prototype
I added a workaround which should fix a big part of cases by patching |
We used this general function to normalize native promises returned from /**
* Normalize promises that are not feature complete.
*
* @param original {Promise} Native or normalized promise.
* @returns {Promise} Normalized feature-complete core-js promise with support for .finally().
*/
export function normalizePromise(original) {
return new Promise((resolve, reject) => {
original.then(resolve).catch(reject)
})
} E.g. return normalizePromise(window.stripe.createToken(element, params)) |
@BevanR That seems like a longer version of |
@loganfsmyth Indeed. Very nice. |
I spotted an issue with using native async functions with the
Promise.prototype.finally
polyfill. The issue comes about when usingcore-js
in conjunction with@babel/preset-env
with a browser that supports native async functions but notPromise.prototype.finally
(e.g. Edge 17). It appears that the globalPromise
object is polyfilled but thePromise
returned from an async function is not.Repo with example to reproduce: https://github.com/vetruvet/async-finally-promise-bug
In that repo,
master
has a demo of the issue (open in Edge to see it fail).Interestingly, simply setting
Promise.prototype.finally
to a dummy function propagates that function to thePromise
returned by async functions (not-a-polyfill-demo
branch in the above repo demonstrates this). Obviously the callback passed in does not get called but the intention is to demonstrate that settingfinally
onPromise.prototype
affects the promise returned by async functions.I am currently working around the bug in a hacky way (
workaround
branch in the above repo) by copyingfinally
to the async function'sPromise
prototype and that seems to be working but obviously I think there should be a proper fix for this.Also of note is that
try { await ...; } catch (e) { ... } finally { ... }
works just fine in Edge, just not calling.finally(...)
on the return value of an async function.The text was updated successfully, but these errors were encountered: