browser.js 561 B

12345678910111213141516171819202122232425262728
  1. 'use strict';
  2. var core = require('./core');
  3. function unwrapEvent(event) {
  4. if (event && event.detail && event.detail.promise) {
  5. return event.detail;
  6. }
  7. return event;
  8. }
  9. module.exports = function (w) {
  10. w = w || window;
  11. var c = core();
  12. w.addEventListener('unhandledrejection', function (event) {
  13. event = unwrapEvent(event);
  14. c.onUnhandledRejection(event.reason, event.promise);
  15. });
  16. w.addEventListener('rejectionhandled', function (event) {
  17. event = unwrapEvent(event);
  18. c.onRejectionHandled(event.promise);
  19. });
  20. return c.currentlyUnhandled;
  21. };