From 79ace5cfcc093f9a62fb1a3f260a37a91b9f4f39 Mon Sep 17 00:00:00 2001 From: Denis Pushkarev Date: Mon, 4 Mar 2024 07:22:47 +0700 Subject: [PATCH] add a fix for Bun `queueMicrotask` arity https://github.com/oven-sh/bun/issues/9249 --- CHANGELOG.md | 1 + packages/core-js-compat/src/data.mjs | 3 ++- packages/core-js/modules/web.queue-microtask.js | 13 ++++++++++++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 58f33b6726f1..f993837d6635 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ##### Unreleased - Fixed some validation cases in `Object.setPrototypeOf`, [#1329](https://github.com/zloirock/core-js/issues/1329), thanks [**@minseok-choe**](https://github.com/minseok-choe) - Fixed the order of validations in `Array.from`, [#1331](https://github.com/zloirock/core-js/pull/1331), thanks [**@minseok-choe**](https://github.com/minseok-choe) +- Added a fix of [Bun `queueMicrotask` arity](https://github.com/oven-sh/bun/issues/9249) - Compat data improvements: - Added React Native 0.74 Hermes compat data, `Array.prototype.{ toSpliced, toReversed, with }` and `atob` marked as supported - Added Opera Android 81 compat data mapping diff --git a/packages/core-js-compat/src/data.mjs b/packages/core-js-compat/src/data.mjs index 942bf9c6475e..ef22e19f72fe 100644 --- a/packages/core-js-compat/src/data.mjs +++ b/packages/core-js-compat/src/data.mjs @@ -2549,7 +2549,8 @@ export const data = { node: '0.9.1', }, 'web.queue-microtask': { - bun: '0.1.1', + // wrong arity in Bun ~ 1.0.30, https://github.com/oven-sh/bun/issues/9249 + // bun: '0.1.1', chrome: '71', deno: '1.0', firefox: '69', diff --git a/packages/core-js/modules/web.queue-microtask.js b/packages/core-js/modules/web.queue-microtask.js index 093c8fbe3942..b5c34d373fa2 100644 --- a/packages/core-js/modules/web.queue-microtask.js +++ b/packages/core-js/modules/web.queue-microtask.js @@ -1,12 +1,23 @@ 'use strict'; var $ = require('../internals/export'); +var globalThis = require('../internals/global'); var microtask = require('../internals/microtask'); var aCallable = require('../internals/a-callable'); var validateArgumentsLength = require('../internals/validate-arguments-length'); +var fails = require('../internals/fails'); +var DESCRIPTORS = require('../internals/descriptors'); + +// Bun ~ 1.0.30 bug +// https://github.com/oven-sh/bun/issues/9249 +var WRONG_ARITY = fails(function () { + // getOwnPropertyDescriptor for prevent experemental warning in Node 11 + // eslint-disable-next-line es/no-object-getownpropertydescriptor -- safe + return DESCRIPTORS && Object.getOwnPropertyDescriptor(globalThis, 'queueMicrotask').value.length !== 1; +}); // `queueMicrotask` method // https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#dom-queuemicrotask -$({ global: true, enumerable: true, dontCallGetSet: true }, { +$({ global: true, enumerable: true, dontCallGetSet: true, forced: WRONG_ARITY }, { queueMicrotask: function queueMicrotask(fn) { validateArgumentsLength(arguments.length, 1); microtask(aCallable(fn));