diff --git a/CHANGELOG.md b/CHANGELOG.md index 3739057714a6..9a3df13e7186 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ ## Changelog ##### Unreleased -- Nothing +- Polyfill `Promise` with `unhandledrejection` event support (browser style) in Deno < [1.24](https://github.com/denoland/deno/releases/tag/v1.24.0) ##### [3.23.5 - 2022.07.18](https://github.com/zloirock/core-js/releases/tag/v3.23.5) - Fixed a typo in the `structuredClone` feature detection, [#1106](https://github.com/zloirock/core-js/issues/1106) diff --git a/packages/core-js-compat/src/data.mjs b/packages/core-js-compat/src/data.mjs index db8dbd679203..5018efc8109e 100644 --- a/packages/core-js-compat/src/data.mjs +++ b/packages/core-js-compat/src/data.mjs @@ -924,6 +924,8 @@ export const data = { 'es.promise': { // V8 6.6 has a serious bug chrome: '67', // '51', + // `unhandledrejection` event support was added in Deno@1.24 + deno: '1.24', firefox: '69', safari: '11.0', rhino: '1.7.14', @@ -931,28 +933,38 @@ export const data = { 'es.promise.constructor': { // V8 6.6 has a serious bug chrome: '67', // '51', + // `unhandledrejection` event support was added in Deno@1.24 + deno: '1.24', firefox: '69', safari: '11.0', rhino: '1.7.14', }, 'es.promise.all': { chrome: '67', + // `unhandledrejection` event support was added in Deno@1.24 + deno: '1.24', firefox: '69', safari: '11.0', rhino: '1.7.14', }, 'es.promise.all-settled': { chrome: '76', + // `unhandledrejection` event support was added in Deno@1.24 + deno: '1.24', firefox: '71', safari: '13', }, 'es.promise.any': { chrome: '85', + // `unhandledrejection` event support was added in Deno@1.24 + deno: '1.24', firefox: '79', safari: '14.0', }, 'es.promise.catch': { chrome: '67', + // `unhandledrejection` event support was added in Deno@1.24 + deno: '1.24', firefox: '69', safari: '11.0', rhino: '1.7.14', @@ -960,6 +972,8 @@ export const data = { 'es.promise.finally': { // V8 6.6 has a serious bug chrome: '67', // '63', + // `unhandledrejection` event support was added in Deno@1.24 + deno: '1.24', firefox: '69', // Previous versions are non-generic // https://bugs.webkit.org/show_bug.cgi?id=200788 @@ -969,18 +983,24 @@ export const data = { }, 'es.promise.race': { chrome: '67', + // `unhandledrejection` event support was added in Deno@1.24 + deno: '1.24', firefox: '69', safari: '11.0', rhino: '1.7.14', }, 'es.promise.reject': { chrome: '67', + // `unhandledrejection` event support was added in Deno@1.24 + deno: '1.24', firefox: '69', safari: '11.0', rhino: '1.7.14', }, 'es.promise.resolve': { chrome: '67', + // `unhandledrejection` event support was added in Deno@1.24 + deno: '1.24', firefox: '69', safari: '11.0', rhino: '1.7.14', diff --git a/packages/core-js/internals/promise-constructor-detection.js b/packages/core-js/internals/promise-constructor-detection.js index 3583dbfd46de..dc3baf3c2d9a 100644 --- a/packages/core-js/internals/promise-constructor-detection.js +++ b/packages/core-js/internals/promise-constructor-detection.js @@ -5,6 +5,7 @@ var isForced = require('../internals/is-forced'); var inspectSource = require('../internals/inspect-source'); var wellKnownSymbol = require('../internals/well-known-symbol'); var IS_BROWSER = require('../internals/engine-is-browser'); +var IS_DENO = require('../internals/engine-is-deno'); var IS_PURE = require('../internals/is-pure'); var V8_VERSION = require('../internals/engine-v8-version'); @@ -25,18 +26,18 @@ var FORCED_PROMISE_CONSTRUCTOR = isForced('Promise', function () { // We can't use @@species feature detection in V8 since it causes // deoptimization and performance degradation // https://github.com/zloirock/core-js/issues/679 - if (V8_VERSION >= 51 && /native code/.test(PROMISE_CONSTRUCTOR_SOURCE)) return false; - // Detect correctness of subclassing with @@species support - var promise = new NativePromiseConstructor(function (resolve) { resolve(1); }); - var FakePromise = function (exec) { - exec(function () { /* empty */ }, function () { /* empty */ }); - }; - var constructor = promise.constructor = {}; - constructor[SPECIES] = FakePromise; - SUBCLASSING = promise.then(function () { /* empty */ }) instanceof FakePromise; - if (!SUBCLASSING) return true; + if (V8_VERSION < 51 || !/native code/.test(PROMISE_CONSTRUCTOR_SOURCE)) { + // Detect correctness of subclassing with @@species support + var promise = new NativePromiseConstructor(function (resolve) { resolve(1); }); + var FakePromise = function (exec) { + exec(function () { /* empty */ }, function () { /* empty */ }); + }; + var constructor = promise.constructor = {}; + constructor[SPECIES] = FakePromise; + SUBCLASSING = promise.then(function () { /* empty */ }) instanceof FakePromise; + if (!SUBCLASSING) return true; // Unhandled rejections tracking support, NodeJS Promise without it fails @@species test - return !GLOBAL_CORE_JS_PROMISE && IS_BROWSER && !NATIVE_PROMISE_REJECTION_EVENT; + } return !GLOBAL_CORE_JS_PROMISE && (IS_BROWSER || IS_DENO) && !NATIVE_PROMISE_REJECTION_EVENT; }); module.exports = { diff --git a/tests/compat/tests.js b/tests/compat/tests.js index 50a12ac20ec7..b37ffd96b137 100644 --- a/tests/compat/tests.js +++ b/tests/compat/tests.js @@ -33,6 +33,8 @@ if (!V8_VERSION && USERAGENT) { var IS_BROWSER = typeof window == 'object' && typeof Deno != 'object'; +var IS_DENO = typeof Deno == 'object' && Deno && typeof Deno.version == 'object'; + // var IS_NODE = Object.prototype.toString.call(process) == '[object process]'; var WEBKIT_STRING_PAD_BUG = /Version\/10(?:\.\d+){1,2}(?: [\w./]+)?(?: Mobile\/\w+)? Safari\//.test(USERAGENT); @@ -59,7 +61,7 @@ var PROMISES_SUPPORT = function () { return promise.then(empty) instanceof FakePromise && V8_VERSION !== 66 - && (!IS_BROWSER || typeof PromiseRejectionEvent == 'function'); + && (!(IS_BROWSER || IS_DENO) || typeof PromiseRejectionEvent == 'function'); }; var PROMISE_STATICS_ITERATION = function () {