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

window.onunhandledrejection called twice #760

Closed
clemp6r opened this issue Jan 28, 2020 · 1 comment
Closed

window.onunhandledrejection called twice #760

clemp6r opened this issue Jan 28, 2020 · 1 comment

Comments

@clemp6r
Copy link

clemp6r commented Jan 28, 2020

Hi, in a browser environment, we have a callback defined as:

window.onunhandledrejection = ...

In case of unhandled promise rejection, our callback is called twice.
We inspected core-js source code and the problem seems to be in es.promise.js:

var dispatchEvent = function (name, promise, reason) {
  var event, handler;
  if (DISPATCH_EVENT) {
    event = document.createEvent('Event');
    event.promise = promise;
    event.reason = reason;
    event.initEvent(name, false, true);
    global.dispatchEvent(event);
  } else event = { promise: promise, reason: reason };
  if (handler = global['on' + name]) handler(event);
  else if (name === UNHANDLED_REJECTION) hostReportErrors('Unhandled promise rejection', reason);
};

Indeed, it seems in modern browser implementations global.dispatchEvent(event); calls the window.onunhandledrejection callback if the event type is unhandledrejection.

Two lines after, if (handler = global['on' + name]) handler(event); calls the exact same callback, as global == window and 'on' + name == onunhandledrejection.

Did I miss something? Is it a core-js bug?

@clemp6r
Copy link
Author

clemp6r commented Feb 10, 2020

I close the issue because this might have been caused by a hack we had to force usage of core-js Promise polyfill even on modern Browsers (delete window.Promise;).

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

1 participant