Skip to content

Commit

Permalink
fix possible twice call of window.onunhandledrejection, #760
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed Nov 6, 2020
1 parent ce6673a commit fb28f12
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- `process.nextTick` have a less priority when `Promise` in the microtask implementation, [#855](https://github.com/zloirock/core-js/issues/855)
- Fixed microtask implementation in engines with `MutationObserver`, but without `document`, [#865](https://github.com/zloirock/core-js/issues/865), [#866](https://github.com/zloirock/core-js/issues/866)
- Fixed `core-js-builder` with an empty (after the targets engines or another filtration) modules list, [#822](https://github.com/zloirock/core-js/issues/822)
- Fixed possible twice call of `window.onunhandledrejection`, [#760](https://github.com/zloirock/core-js/issues/760)
- Added a workaround for 3rd party `Reflect.set` polyfill bug, [#847](https://github.com/zloirock/core-js/issues/847)
- Forced replacement of `Array#{ reduce, reduceRight }` in Chrome 80-82 because of [a bug](https://bugs.chromium.org/p/chromium/issues/detail?id=1049982), [#766](https://github.com/zloirock/core-js/issues/766)
- Updated compat data:
Expand Down
5 changes: 3 additions & 2 deletions packages/core-js/modules/es.promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ var $fetch = getBuiltIn('fetch');
var newPromiseCapability = newPromiseCapabilityModule.f;
var newGenericPromiseCapability = newPromiseCapability;
var DISPATCH_EVENT = !!(document && document.createEvent && global.dispatchEvent);
var NATIVE_REJECTION_EVENT = typeof PromiseRejectionEvent == 'function';
var UNHANDLED_REJECTION = 'unhandledrejection';
var REJECTION_HANDLED = 'rejectionhandled';
var PENDING = 0;
Expand All @@ -57,7 +58,7 @@ var FORCED = isForced(PROMISE, function () {
// We can't detect it synchronously, so just check versions
if (V8_VERSION === 66) return true;
// Unhandled rejections tracking support, NodeJS Promise without it fails @@species test
if (!IS_NODE && typeof PromiseRejectionEvent != 'function') return true;
if (!IS_NODE && !NATIVE_REJECTION_EVENT) return true;
}
// We need Promise#finally in the pure version for preventing prototype pollution
if (IS_PURE && !PromiseConstructor.prototype['finally']) return true;
Expand Down Expand Up @@ -142,7 +143,7 @@ var dispatchEvent = function (name, promise, reason) {
event.initEvent(name, false, true);
global.dispatchEvent(event);
} else event = { promise: promise, reason: reason };
if (handler = global['on' + name]) handler(event);
if (!NATIVE_REJECTION_EVENT && (handler = global['on' + name])) handler(event);
else if (name === UNHANDLED_REJECTION) hostReportErrors('Unhandled promise rejection', reason);
};

Expand Down

0 comments on commit fb28f12

Please sign in to comment.