Skip to content

Commit 4a29d1f

Browse files
committed
fix URLSearchParams iterator .next that should be enumerable by the spec
https://webidl.spec.whatwg.org/#es-iterator-prototype-object
1 parent bfa8fe1 commit 4a29d1f

File tree

5 files changed

+25
-3
lines changed

5 files changed

+25
-3
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## Changelog
22
##### Unreleased
33
- Fixed requirements of internal slots in `Observable` / `Subscription` / `SubscriptionObserver`, [#1017](https://github.com/zloirock/core-js/issues/1017)
4+
- Fixed `URLSearchParams` iterator `.next` that should be enumerable [by the spec](https://webidl.spec.whatwg.org/#es-iterator-prototype-object)
45
- Added NodeJS 17.2 compat data mapping
56

67
##### 3.19.2 - 2021.11.29

packages/core-js/internals/create-iterator-constructor.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ var Iterators = require('../internals/iterators');
77

88
var returnThis = function () { return this; };
99

10-
module.exports = function (IteratorConstructor, NAME, next) {
10+
module.exports = function (IteratorConstructor, NAME, next, ENUMERABLE_NEXT) {
1111
var TO_STRING_TAG = NAME + ' Iterator';
12-
IteratorConstructor.prototype = create(IteratorPrototype, { next: createPropertyDescriptor(1, next) });
12+
IteratorConstructor.prototype = create(IteratorPrototype, { next: createPropertyDescriptor(+!ENUMERABLE_NEXT, next) });
1313
setToStringTag(IteratorConstructor, TO_STRING_TAG, false, true);
1414
Iterators[TO_STRING_TAG] = returnThis;
1515
return IteratorConstructor;

packages/core-js/modules/web.url-search-params.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ var URLSearchParamsIterator = createIteratorConstructor(function Iterator(params
117117
if (!step.done) {
118118
step.value = kind === 'keys' ? entry.key : kind === 'values' ? entry.value : [entry.key, entry.value];
119119
} return step;
120-
});
120+
}, true);
121121

122122
var URLSearchParamsState = function (init) {
123123
this.entries = [];

tests/pure/web.url-search-params.js

+11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { DESCRIPTORS } from '../helpers/constants';
22
import { createIterable } from '../helpers/helpers';
33

4+
import getPrototypeOf from 'core-js-pure/es/object/get-prototype-of';
5+
import getOwnPropertyDescriptor from 'core-js-pure/es/object/get-own-property-descriptor';
6+
47
import { Symbol, URL, URLSearchParams } from 'core-js-pure';
58

69
QUnit.test('URLSearchParams', assert => {
@@ -684,6 +687,8 @@ QUnit.test('URLSearchParams#entries', assert => {
684687
result += key + value;
685688
}
686689
assert.same(result, 'a1c3');
690+
691+
assert.true(getOwnPropertyDescriptor(getPrototypeOf(new URLSearchParams().entries()), 'next').enumerable, 'enumerable .next');
687692
});
688693

689694
QUnit.test('URLSearchParams#keys', assert => {
@@ -725,6 +730,8 @@ QUnit.test('URLSearchParams#keys', assert => {
725730
result += key;
726731
}
727732
assert.same(result, 'ac');
733+
734+
assert.true(getOwnPropertyDescriptor(getPrototypeOf(new URLSearchParams().keys()), 'next').enumerable, 'enumerable .next');
728735
});
729736

730737
QUnit.test('URLSearchParams#values', assert => {
@@ -766,6 +773,8 @@ QUnit.test('URLSearchParams#values', assert => {
766773
result += key;
767774
}
768775
assert.same(result, '13');
776+
777+
assert.true(getOwnPropertyDescriptor(getPrototypeOf(new URLSearchParams().values()), 'next').enumerable, 'enumerable .next');
769778
});
770779

771780
QUnit.test('URLSearchParams#@@iterator', assert => {
@@ -813,4 +822,6 @@ QUnit.test('URLSearchParams#@@iterator', assert => {
813822
result += key + value;
814823
}
815824
assert.same(result, 'a1c3');
825+
826+
assert.true(getOwnPropertyDescriptor(getPrototypeOf(new URLSearchParams()[Symbol.iterator]()), 'next').enumerable, 'enumerable .next');
816827
});

tests/tests/web.url-search-params.js

+10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { DESCRIPTORS, NODE } from '../helpers/constants';
22
import { createIterable } from '../helpers/helpers';
33

4+
const { getPrototypeOf, getOwnPropertyDescriptor } = Object;
5+
46
QUnit.test('URLSearchParams', assert => {
57
assert.isFunction(URLSearchParams);
68
assert.arity(URLSearchParams, 0);
@@ -703,6 +705,8 @@ QUnit.test('URLSearchParams#entries', assert => {
703705
result += key + value;
704706
}
705707
assert.same(result, 'a1c3');
708+
709+
assert.true(getOwnPropertyDescriptor(getPrototypeOf(new URLSearchParams().entries()), 'next').enumerable, 'enumerable .next');
706710
});
707711

708712
QUnit.test('URLSearchParams#keys', assert => {
@@ -746,6 +750,8 @@ QUnit.test('URLSearchParams#keys', assert => {
746750
result += key;
747751
}
748752
assert.same(result, 'ac');
753+
754+
assert.true(getOwnPropertyDescriptor(getPrototypeOf(new URLSearchParams().keys()), 'next').enumerable, 'enumerable .next');
749755
});
750756

751757
QUnit.test('URLSearchParams#values', assert => {
@@ -789,6 +795,8 @@ QUnit.test('URLSearchParams#values', assert => {
789795
result += key;
790796
}
791797
assert.same(result, '13');
798+
799+
assert.true(getOwnPropertyDescriptor(getPrototypeOf(new URLSearchParams().values()), 'next').enumerable, 'enumerable .next');
792800
});
793801

794802
QUnit.test('URLSearchParams#@@iterator', assert => {
@@ -838,6 +846,8 @@ QUnit.test('URLSearchParams#@@iterator', assert => {
838846
result += key + value;
839847
}
840848
assert.same(result, 'a1c3');
849+
850+
assert.true(getOwnPropertyDescriptor(getPrototypeOf(new URLSearchParams()[Symbol.iterator]()), 'next').enumerable, 'enumerable .next');
841851
});
842852

843853
QUnit.test('URLSearchParams#@@toStringTag', assert => {

0 commit comments

Comments
 (0)