Skip to content

Commit

Permalink
fix URLSearchParams iterator .next that should be enumerable by t…
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed Dec 3, 2021
1 parent bfa8fe1 commit 4a29d1f
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## Changelog
##### Unreleased
- Fixed requirements of internal slots in `Observable` / `Subscription` / `SubscriptionObserver`, [#1017](https://github.com/zloirock/core-js/issues/1017)
- Fixed `URLSearchParams` iterator `.next` that should be enumerable [by the spec](https://webidl.spec.whatwg.org/#es-iterator-prototype-object)
- Added NodeJS 17.2 compat data mapping

##### 3.19.2 - 2021.11.29
Expand Down
4 changes: 2 additions & 2 deletions packages/core-js/internals/create-iterator-constructor.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ var Iterators = require('../internals/iterators');

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

module.exports = function (IteratorConstructor, NAME, next) {
module.exports = function (IteratorConstructor, NAME, next, ENUMERABLE_NEXT) {
var TO_STRING_TAG = NAME + ' Iterator';
IteratorConstructor.prototype = create(IteratorPrototype, { next: createPropertyDescriptor(1, next) });
IteratorConstructor.prototype = create(IteratorPrototype, { next: createPropertyDescriptor(+!ENUMERABLE_NEXT, next) });
setToStringTag(IteratorConstructor, TO_STRING_TAG, false, true);
Iterators[TO_STRING_TAG] = returnThis;
return IteratorConstructor;
Expand Down
2 changes: 1 addition & 1 deletion packages/core-js/modules/web.url-search-params.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ var URLSearchParamsIterator = createIteratorConstructor(function Iterator(params
if (!step.done) {
step.value = kind === 'keys' ? entry.key : kind === 'values' ? entry.value : [entry.key, entry.value];
} return step;
});
}, true);

var URLSearchParamsState = function (init) {
this.entries = [];
Expand Down
11 changes: 11 additions & 0 deletions tests/pure/web.url-search-params.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { DESCRIPTORS } from '../helpers/constants';
import { createIterable } from '../helpers/helpers';

import getPrototypeOf from 'core-js-pure/es/object/get-prototype-of';
import getOwnPropertyDescriptor from 'core-js-pure/es/object/get-own-property-descriptor';

import { Symbol, URL, URLSearchParams } from 'core-js-pure';

QUnit.test('URLSearchParams', assert => {
Expand Down Expand Up @@ -684,6 +687,8 @@ QUnit.test('URLSearchParams#entries', assert => {
result += key + value;
}
assert.same(result, 'a1c3');

assert.true(getOwnPropertyDescriptor(getPrototypeOf(new URLSearchParams().entries()), 'next').enumerable, 'enumerable .next');
});

QUnit.test('URLSearchParams#keys', assert => {
Expand Down Expand Up @@ -725,6 +730,8 @@ QUnit.test('URLSearchParams#keys', assert => {
result += key;
}
assert.same(result, 'ac');

assert.true(getOwnPropertyDescriptor(getPrototypeOf(new URLSearchParams().keys()), 'next').enumerable, 'enumerable .next');
});

QUnit.test('URLSearchParams#values', assert => {
Expand Down Expand Up @@ -766,6 +773,8 @@ QUnit.test('URLSearchParams#values', assert => {
result += key;
}
assert.same(result, '13');

assert.true(getOwnPropertyDescriptor(getPrototypeOf(new URLSearchParams().values()), 'next').enumerable, 'enumerable .next');
});

QUnit.test('URLSearchParams#@@iterator', assert => {
Expand Down Expand Up @@ -813,4 +822,6 @@ QUnit.test('URLSearchParams#@@iterator', assert => {
result += key + value;
}
assert.same(result, 'a1c3');

assert.true(getOwnPropertyDescriptor(getPrototypeOf(new URLSearchParams()[Symbol.iterator]()), 'next').enumerable, 'enumerable .next');
});
10 changes: 10 additions & 0 deletions tests/tests/web.url-search-params.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { DESCRIPTORS, NODE } from '../helpers/constants';
import { createIterable } from '../helpers/helpers';

const { getPrototypeOf, getOwnPropertyDescriptor } = Object;

QUnit.test('URLSearchParams', assert => {
assert.isFunction(URLSearchParams);
assert.arity(URLSearchParams, 0);
Expand Down Expand Up @@ -703,6 +705,8 @@ QUnit.test('URLSearchParams#entries', assert => {
result += key + value;
}
assert.same(result, 'a1c3');

assert.true(getOwnPropertyDescriptor(getPrototypeOf(new URLSearchParams().entries()), 'next').enumerable, 'enumerable .next');
});

QUnit.test('URLSearchParams#keys', assert => {
Expand Down Expand Up @@ -746,6 +750,8 @@ QUnit.test('URLSearchParams#keys', assert => {
result += key;
}
assert.same(result, 'ac');

assert.true(getOwnPropertyDescriptor(getPrototypeOf(new URLSearchParams().keys()), 'next').enumerable, 'enumerable .next');
});

QUnit.test('URLSearchParams#values', assert => {
Expand Down Expand Up @@ -789,6 +795,8 @@ QUnit.test('URLSearchParams#values', assert => {
result += key;
}
assert.same(result, '13');

assert.true(getOwnPropertyDescriptor(getPrototypeOf(new URLSearchParams().values()), 'next').enumerable, 'enumerable .next');
});

QUnit.test('URLSearchParams#@@iterator', assert => {
Expand Down Expand Up @@ -838,6 +846,8 @@ QUnit.test('URLSearchParams#@@iterator', assert => {
result += key + value;
}
assert.same(result, 'a1c3');

assert.true(getOwnPropertyDescriptor(getPrototypeOf(new URLSearchParams()[Symbol.iterator]()), 'next').enumerable, 'enumerable .next');
});

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

0 comments on commit 4a29d1f

Please sign in to comment.