Skip to content

Commit

Permalink
fix incorrect Symbol.{ dispose, asyncDispose } descriptors from Nod…
Browse files Browse the repository at this point in the history
…eJS 20.4 / transpilers helpers / userland code
  • Loading branch information
zloirock committed Jul 26, 2023
1 parent d9b3fdc commit ce0913b
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 9 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Expand Up @@ -39,12 +39,13 @@
- `DataView.prototype.setUint8Clamped`
- Used strict mode in some missed cases, [#1269](https://github.com/zloirock/core-js/issues/1269)
- Fixed [a Chromium 117 bug](https://bugs.chromium.org/p/v8/issues/detail?id=14222) in `value` argument of `URLSearchParams.prototype.{ has, delete }`
- Fixed incorrect `Symbol.{ dispose, asyncDispose }` descriptors from [NodeJS 20.4](https://github.com/nodejs/node/issues/48699) / transpilers helpers / userland code
- Fixed forced polyfilling of some iterator helpers that should return wrapped iterator in the pure version
- Fixed and exposed [`AsyncIteratorPrototype` `core-js/configurator` option](https://github.com/zloirock/core-js#asynciterator-helpers), [#1268](https://github.com/zloirock/core-js/issues/1268)
- Compat data improvements:
- Sync [`Iterator` helpers proposal](https://github.com/tc39/proposal-iterator-helpers) features marked as [supported](https://chromestatus.com/feature/5102502917177344) from V8 ~ Chrome 117
- [`Array` grouping proposal](https://github.com/tc39/proposal-array-grouping) features marked as [supported](https://chromestatus.com/feature/5714791975878656) from V8 ~ Chrome 117
- [NodeJS 20.4.0 add `Symbol.{ dispose, asyncDispose }`](https://github.com/nodejs/node/pull/48518), but [with incorrect property descriptors](https://github.com/nodejs/node/issues/48699)
- Mark `Symbol.{ dispose, asyncDispose }` as supported from NodeJS 20.5.0 (as mentioned above, NodeJS 20.4.0 add it, but [with incorrect descriptors](https://github.com/nodejs/node/issues/48699))
- Added Electron 27 compat data mapping

##### [3.31.1 - 2023.07.06](https://github.com/zloirock/core-js/releases/tag/v3.31.1)
Expand Down
6 changes: 4 additions & 2 deletions packages/core-js-compat/src/data.mjs
Expand Up @@ -2285,11 +2285,13 @@ export const data = {
'esnext.string.to-well-formed': null,
'esnext.symbol.async-dispose': {
// Node 20.4.0 add `Symbol.asyncDispose`, but with incorrect descriptor
node: '20.4.0',
// https://github.com/nodejs/node/issues/48699
node: '20.5.0',
},
'esnext.symbol.dispose': {
// Node 20.4.0 add `Symbol.dispose`, but with incorrect descriptor
node: '20.4.0',
// https://github.com/nodejs/node/issues/48699
node: '20.5.0',
},
'esnext.symbol.is-registered-symbol': {
},
Expand Down
@@ -0,0 +1,6 @@
'use strict';
var defineWellKnownSymbol = require('../internals/well-known-symbol-define');

// `Symbol.asyncDispose` well-known symbol
// https://github.com/tc39/proposal-async-explicit-resource-management
defineWellKnownSymbol('asyncDispose');
@@ -0,0 +1,6 @@
'use strict';
var defineWellKnownSymbol = require('../internals/well-known-symbol-define');

// `Symbol.dispose` well-known symbol
// https://github.com/tc39/proposal-explicit-resource-management
defineWellKnownSymbol('dispose');
15 changes: 15 additions & 0 deletions packages/core-js/modules/esnext.symbol.async-dispose.js
@@ -1,6 +1,21 @@
'use strict';
var global = require('../internals/global');
var defineWellKnownSymbol = require('../internals/well-known-symbol-define');
var defineProperty = require('../internals/object-define-property').f;
var getOwnPropertyDescriptor = require('../internals/object-get-own-property-descriptor').f;

var Symbol = global.Symbol;

// `Symbol.asyncDispose` well-known symbol
// https://github.com/tc39/proposal-async-explicit-resource-management
defineWellKnownSymbol('asyncDispose');

if (Symbol) {
var descriptor = getOwnPropertyDescriptor(Symbol, 'asyncDispose');
// workaround of NodeJS 20.4 bug
// https://github.com/nodejs/node/issues/48699
// and incorrect descriptor from some transpilers and userland helpers
if (descriptor.enumerable && descriptor.configurable && descriptor.writable) {
defineProperty(Symbol, 'asyncDispose', { value: descriptor.value, enumerable: false, configurable: false, writable: false });
}
}
15 changes: 15 additions & 0 deletions packages/core-js/modules/esnext.symbol.dispose.js
@@ -1,6 +1,21 @@
'use strict';
var global = require('../internals/global');
var defineWellKnownSymbol = require('../internals/well-known-symbol-define');
var defineProperty = require('../internals/object-define-property').f;
var getOwnPropertyDescriptor = require('../internals/object-get-own-property-descriptor').f;

var Symbol = global.Symbol;

// `Symbol.dispose` well-known symbol
// https://github.com/tc39/proposal-explicit-resource-management
defineWellKnownSymbol('dispose');

if (Symbol) {
var descriptor = getOwnPropertyDescriptor(Symbol, 'dispose');
// workaround of NodeJS 20.4 bug
// https://github.com/nodejs/node/issues/48699
// and incorrect descriptor from some transpilers and userland helpers
if (descriptor.enumerable && descriptor.configurable && descriptor.writable) {
defineProperty(Symbol, 'dispose', { value: descriptor.value, enumerable: false, configurable: false, writable: false });
}
}
6 changes: 4 additions & 2 deletions tests/compat/tests.js
Expand Up @@ -1789,10 +1789,12 @@ GLOBAL.tests = {
return String.dedent;
},
'esnext.symbol.async-dispose': function () {
return Symbol.dispose;
var descriptor = Object.getOwnPropertyDescriptor(Symbol, 'asyncDispose');
return descriptor.value && !descriptor.enumerable && !descriptor.configurable && !descriptor.writable;
},
'esnext.symbol.dispose': function () {
return Symbol.dispose;
var descriptor = Object.getOwnPropertyDescriptor(Symbol, 'dispose');
return descriptor.value && !descriptor.enumerable && !descriptor.configurable && !descriptor.writable;
},
'esnext.symbol.is-registered-symbol': function () {
return Symbol.isRegisteredSymbol;
Expand Down
4 changes: 2 additions & 2 deletions tests/unit-global/esnext.symbol.async-dispose.js
@@ -1,11 +1,11 @@
import { DESCRIPTORS, GLOBAL } from '../helpers/constants';
import { DESCRIPTORS } from '../helpers/constants';

QUnit.test('Symbol.asyncDispose', assert => {
assert.true('asyncDispose' in Symbol, 'Symbol.asyncDispose available');
assert.true(Object(Symbol.asyncDispose) instanceof Symbol, 'Symbol.asyncDispose is symbol');
// Node 20.4.0 add `Symbol.asyncDispose`, but with incorrect descriptor
// https://github.com/nodejs/node/issues/48699
if (DESCRIPTORS && GLOBAL.process?.versions?.node !== '20.4.0') {
if (DESCRIPTORS) {
const descriptor = Object.getOwnPropertyDescriptor(Symbol, 'asyncDispose');
assert.false(descriptor.enumerable, 'non-enumerable');
assert.false(descriptor.writable, 'non-writable');
Expand Down
4 changes: 2 additions & 2 deletions tests/unit-global/esnext.symbol.dispose.js
@@ -1,11 +1,11 @@
import { DESCRIPTORS, GLOBAL } from '../helpers/constants';
import { DESCRIPTORS } from '../helpers/constants';

QUnit.test('Symbol.dispose', assert => {
assert.true('dispose' in Symbol, 'Symbol.dispose available');
assert.true(Object(Symbol.dispose) instanceof Symbol, 'Symbol.dispose is symbol');
// Node 20.4.0 add `Symbol.dispose`, but with incorrect descriptor
// https://github.com/nodejs/node/issues/48699
if (DESCRIPTORS && GLOBAL.process?.versions?.node !== '20.4.0') {
if (DESCRIPTORS) {
const descriptor = Object.getOwnPropertyDescriptor(Symbol, 'dispose');
assert.false(descriptor.enumerable, 'non-enumerable');
assert.false(descriptor.writable, 'non-writable');
Expand Down

0 comments on commit ce0913b

Please sign in to comment.