Skip to content

Commit

Permalink
define @@toStringTag on DOM collections as non-writable, fix #1312
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed Nov 28, 2023
1 parent 4373830 commit 3222dbc
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- `Promise.withResolvers`
- Moved to stable ES, [November 2023 TC39 meeting](https://twitter.com/robpalmer2/status/1729216597623976407)
- Added `es.` namespace module, `/es/` and `/stable/` namespaces entries
- Fixed `@@toStringTag` property descriptors on DOM collections, [#1312](https://github.com/zloirock/core-js/issues/1312)
- Some minor `atob` / `btoa` improvements
- Compat data improvements:
- [`Promise.withResolvers`](https://github.com/tc39/proposal-promise-with-resolvers) marked as shipped from FF121
Expand Down
4 changes: 2 additions & 2 deletions packages/core-js-pure/override/internals/set-to-string-tag.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ var wellKnownSymbol = require('../internals/well-known-symbol');
var TO_STRING_TAG = wellKnownSymbol('toStringTag');

module.exports = function (it, TAG, STATIC, SET_METHOD) {
if (it) {
var target = STATIC ? it : it.prototype;
var target = STATIC ? it : it && it.prototype;
if (target) {
if (!hasOwn(target, TO_STRING_TAG)) {
defineProperty(target, TO_STRING_TAG, { configurable: true, value: TAG });
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,10 @@
require('../modules/es.array.iterator');
var DOMIterables = require('../internals/dom-iterables');
var global = require('../internals/global');
var classof = require('../internals/classof');
var createNonEnumerableProperty = require('../internals/create-non-enumerable-property');
var setToStringTag = require('../internals/set-to-string-tag');
var Iterators = require('../internals/iterators');
var wellKnownSymbol = require('../internals/well-known-symbol');

var TO_STRING_TAG = wellKnownSymbol('toStringTag');

for (var COLLECTION_NAME in DOMIterables) {
var Collection = global[COLLECTION_NAME];
var CollectionPrototype = Collection && Collection.prototype;
if (CollectionPrototype && classof(CollectionPrototype) !== TO_STRING_TAG) {
createNonEnumerableProperty(CollectionPrototype, TO_STRING_TAG, COLLECTION_NAME);
}
setToStringTag(global[COLLECTION_NAME], COLLECTION_NAME);
Iterators[COLLECTION_NAME] = Iterators.Array;
}
6 changes: 2 additions & 4 deletions packages/core-js/modules/web.dom-collections.iterator.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ var DOMIterables = require('../internals/dom-iterables');
var DOMTokenListPrototype = require('../internals/dom-token-list-prototype');
var ArrayIteratorMethods = require('../modules/es.array.iterator');
var createNonEnumerableProperty = require('../internals/create-non-enumerable-property');
var setToStringTag = require('../internals/set-to-string-tag');
var wellKnownSymbol = require('../internals/well-known-symbol');

var ITERATOR = wellKnownSymbol('iterator');
var TO_STRING_TAG = wellKnownSymbol('toStringTag');
var ArrayValues = ArrayIteratorMethods.values;

var handlePrototype = function (CollectionPrototype, COLLECTION_NAME) {
Expand All @@ -18,9 +18,7 @@ var handlePrototype = function (CollectionPrototype, COLLECTION_NAME) {
} catch (error) {
CollectionPrototype[ITERATOR] = ArrayValues;
}
if (!CollectionPrototype[TO_STRING_TAG]) {
createNonEnumerableProperty(CollectionPrototype, TO_STRING_TAG, COLLECTION_NAME);
}
setToStringTag(CollectionPrototype, COLLECTION_NAME, true);
if (DOMIterables[COLLECTION_NAME]) for (var METHOD_NAME in ArrayIteratorMethods) {
// some Chrome versions have non-configurable methods on DOMTokenList
if (CollectionPrototype[METHOD_NAME] !== ArrayIteratorMethods[METHOD_NAME]) try {
Expand Down

0 comments on commit 3222dbc

Please sign in to comment.