Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Iterator Helpers #2818

Merged
merged 68 commits into from
Jun 15, 2023
Merged
Show file tree
Hide file tree
Changes from 65 commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
846527d
AsyncIterator, pt 1
rwaldron Dec 2, 2021
fb1ec43
AsyncIterator, pt 1
rwaldron Sep 24, 2020
3cbd492
AsyncIterator, pt 2
rwaldron Nov 4, 2020
d11190b
AsyncIterator, pt 3
rwaldron Dec 2, 2020
796d915
AsyncIterator, pt 4
rwaldron Dec 2, 2020
4d84bb5
Lint fix
rwaldron Dec 2, 2020
1ffd654
WIP: split iterator helpers proposal into sync/async
michaelficarra Mar 8, 2023
a77da9d
WIP: split iterator helpers proposal into sync/async (drop)
michaelficarra Mar 9, 2023
738e83c
delete asIndexedPairs
michaelficarra Mar 9, 2023
c664108
WIP: split iterator helpers proposal into sync/async (find)
michaelficarra Mar 10, 2023
7bbdc23
WIP: split iterator helpers proposal into sync/async (filter)
michaelficarra Mar 10, 2023
f37c41d
drop
michaelficarra Mar 11, 2023
ee73f08
more drop tests
michaelficarra Mar 13, 2023
7d93b51
more every tests
michaelficarra Mar 14, 2023
1731b9e
finish drop/every
michaelficarra Mar 14, 2023
c240314
missed some
michaelficarra Mar 15, 2023
5961825
more drop/every tests
michaelficarra Mar 16, 2023
9cb3763
another drop/every test
michaelficarra Mar 16, 2023
2d9724e
filter tests
michaelficarra Mar 16, 2023
8394ceb
remove find tests that I'm not going to use
michaelficarra Mar 16, 2023
26c7463
remove Test262AsyncIterator
michaelficarra Mar 18, 2023
7078f1b
remove unused vars
michaelficarra Mar 18, 2023
625ba33
fixup: Apply suggestions from code review
ljharb Mar 22, 2023
b9fd34d
fixup: fix Object toString test
ljharb Mar 25, 2023
3d83a24
add another this/arguments order assertion
michaelficarra Mar 30, 2023
4df6042
add more assertions for forwarding return only once
michaelficarra Mar 30, 2023
0fbe8e2
start of flatMap tests
michaelficarra Mar 31, 2023
e4aa3b3
use verifyProperty
michaelficarra Apr 24, 2023
188b5cc
remove IteratorPrototype
michaelficarra Apr 24, 2023
1daf454
address review comments
michaelficarra Apr 24, 2023
cdbdbee
add some more flatMap tests
michaelficarra Apr 25, 2023
cdf7237
remove unused includes
michaelficarra Apr 25, 2023
dee5d01
remove empty includes
michaelficarra Apr 25, 2023
a50a903
missed one
michaelficarra Apr 25, 2023
d9f1a78
more flatMap tests
michaelficarra Apr 25, 2023
eab8870
add tests for take
michaelficarra Apr 25, 2023
c203788
fix up some things I noticed while writing take tests
michaelficarra Apr 25, 2023
71aa978
remove Test262Iterator helper
michaelficarra Apr 26, 2023
bf25cae
add some step references to flatMap descriptions
michaelficarra Apr 26, 2023
13f20cf
fix broken take test
michaelficarra Apr 28, 2023
3caff9a
add tests for some
michaelficarra Apr 29, 2023
da7cfa2
add tests for map
michaelficarra May 4, 2023
73c93df
add test for forEach
michaelficarra May 5, 2023
e0ffa73
add descriptions about non-constructibility
michaelficarra May 22, 2023
412bcf6
https://github.com/tc39/proposal-iterator-helpers/pull/274
michaelficarra May 22, 2023
8b49bf4
https://github.com/tc39/proposal-iterator-helpers/pull/272
michaelficarra May 22, 2023
8e4974b
add tests for non-constructibility with no arguments
michaelficarra May 22, 2023
dfdd47a
typo
michaelficarra May 22, 2023
1dc86d8
typo
michaelficarra May 22, 2023
61e8521
Iterator.from tests
michaelficarra May 22, 2023
66f41b8
tests for `find`
michaelficarra May 23, 2023
43dc6bf
remove useless assertion messages
michaelficarra May 23, 2023
3c42624
run prettier
michaelficarra May 23, 2023
901f8b1
test for Symbol.toStringTag
michaelficarra May 23, 2023
ffb5f7c
fix length descriptions
michaelficarra May 23, 2023
224854c
remove tautological assertions from property descriptor tests
michaelficarra May 23, 2023
4c2a096
remove more useless assertion messages
michaelficarra May 23, 2023
ed0909a
add toArray tests
michaelficarra May 23, 2023
d39135d
improve the throws-then-closing-iterator-also-throws tests
michaelficarra May 25, 2023
6653018
use prefix increments
michaelficarra May 25, 2023
1f3ac12
add tests for reduce
michaelficarra May 25, 2023
d0913b4
review feedback
michaelficarra May 25, 2023
0d04ba7
don't rely on Iterator global in Symbol.iterator tests
michaelficarra May 31, 2023
b36d1d5
add iteator-helpers feature flag to Symbol.toStringTag test
michaelficarra May 31, 2023
03b56c5
fix broken frontmatter in proto-from-ctor-realm.js
michaelficarra May 31, 2023
6ee276a
fix another leftover Iterator.prototype
michaelficarra Jun 12, 2023
523e08c
Merge branch 'main' into iterator-helpers
michaelficarra Jun 12, 2023
30f9dcf
Merge branch 'main' into iterator-helpers
ptomato Jun 15, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 4 additions & 0 deletions features.txt
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ String.prototype.toWellFormed
# https://github.com/tc39/proposal-json-parse-with-source
json-parse-with-source

# Iterator Helpers
# https://github.com/tc39/proposal-iterator-helpers
iterator-helpers

## Standard language features
#
# Language features that have been included in a published version of the
Expand Down
11 changes: 11 additions & 0 deletions test/built-ins/Iterator/constructor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-iterator-constructor
description: >
The Iterator constructor is a built-in function
features: [iterator-helpers]
---*/

assert.sameValue(typeof Iterator, 'function', 'The value of `typeof Iterator` is "function"');
12 changes: 12 additions & 0 deletions test/built-ins/Iterator/from/callable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iterator.from
description: >
Iterator.from is callable
features: [iterator-helpers]
---*/
function* g() {}

Iterator.from(g());
Iterator.from.call(null, g());
46 changes: 46 additions & 0 deletions test/built-ins/Iterator/from/get-next-method-only-once.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright (C) 2023 Michael Ficarra. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iterator.from
description: >
Gets the next method from the underlying iterator only once
info: |
Iterator.from ( O )

2. Let iteratorRecord be ? GetIteratorFlattenable(O).

features: [iterator-helpers]
flags: []
---*/
let nextGets = 0;
let nextCalls = 0;

class CountingIterator {
get next() {
++nextGets;
let iter = (function* () {
for (let i = 1; i < 5; ++i) {
yield i;
}
})();
return function () {
++nextCalls;
return iter.next();
};
}
}

let iterator = new CountingIterator();

assert.sameValue(nextGets, 0, 'The value of `nextGets` is 0');
assert.sameValue(nextCalls, 0, 'The value of `nextCalls` is 0');

iterator = Iterator.from(iterator);

assert.sameValue(nextGets, 1, 'The value of `nextGets` is 1');
assert.sameValue(nextCalls, 0, 'The value of `nextCalls` is 0');

iterator.toArray();

assert.sameValue(nextGets, 1, 'The value of `nextGets` is 1');
assert.sameValue(nextCalls, 5, 'The value of `nextCalls` is 5');
25 changes: 25 additions & 0 deletions test/built-ins/Iterator/from/get-next-method-throws.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (C) 2023 Michael Ficarra. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iterator.from
description: >
Underlying iterator has throwing next getter
info: |
Iterator.from ( O )

4. Let iterated be ? GetIteratorDirect(O).

features: [iterator-helpers]
flags: []
---*/
class ThrowingIterator {
get next() {
throw new Test262Error();
}
}

let iterator = new ThrowingIterator();

assert.throws(Test262Error, function () {
Iterator.from(iterator);
});
10 changes: 10 additions & 0 deletions test/built-ins/Iterator/from/is-function.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iterator.from
description: >
Iterator.from is a built-in function
features: [iterator-helpers]
---*/

assert.sameValue(typeof Iterator.from, 'function', 'The value of `typeof Iterator.from` is "function"');
39 changes: 39 additions & 0 deletions test/built-ins/Iterator/from/iterable-primitives.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright (C) 2023 Michael Ficarra. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iterator.from
description: >
Iterator.from does not respect the iterability of any primitive except Strings
info: |
Iterator.from ( O )

1. If O is a String, set O to ! ToObject(O).
2. Let iteratorRecord be ? GetIteratorFlattenable(O).

includes: [compareArray.js]
features: [iterator-helpers]
flags: []
---*/

function* g() {
yield 0;
}

Number.prototype[Symbol.iterator] = function* () {
let i = 0;
let target = this >>> 0;
while (i < target) {
yield i;
++i;
}
};

assert.compareArray(Array.from(5), [0, 1, 2, 3, 4]);

assert.throws(TypeError, function () {
Iterator.from(5);
});

assert.compareArray(Array.from(Iterator.from(new Number(5))), [0, 1, 2, 3, 4]);

assert.compareArray(Array.from(Iterator.from('string')), ['s', 't', 'r', 'i', 'n', 'g']);
51 changes: 51 additions & 0 deletions test/built-ins/Iterator/from/iterable-to-iterator-fallback.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright (C) 2023 Michael Ficarra. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iterator.from
description: >
Iterator.from falls back to treating its parameter as an iterator if the Symbol.iterator property is null/undefined
info: |
Iterator.from ( O )

includes: [compareArray.js]
features: [iterator-helpers]
flags: []
---*/

function* g() {
yield 0;
yield 1;
yield 2;
}

let iter = (function () {
let n = g();
return {
[Symbol.iterator]: 0,
next: () => n.next(),
};
})();

assert.throws(TypeError, function () {
Iterator.from(iter);
});

iter = (function () {
let n = g();
return {
[Symbol.iterator]: null,
next: () => n.next(),
};
})();

assert.compareArray(Array.from(Iterator.from(iter)), [0, 1, 2]);

iter = (function () {
let n = g();
return {
[Symbol.iterator]: undefined,
next: () => n.next(),
};
})();

assert.compareArray(Array.from(Iterator.from(iter)), [0, 1, 2]);
22 changes: 22 additions & 0 deletions test/built-ins/Iterator/from/length.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iterator.from
description: >
Iterator.from has a "length" property whose value is 1.
info: |
ECMAScript Standard Built-in Objects

Unless otherwise specified, the length property of a built-in
Function object has the attributes { [[Writable]]: false, [[Enumerable]]:
false, [[Configurable]]: true }.
features: [iterator-helpers]
includes: [propertyHelper.js]
---*/

verifyProperty(Iterator.from, 'length', {
value: 1,
writable: false,
enumerable: false,
configurable: true,
});
29 changes: 29 additions & 0 deletions test/built-ins/Iterator/from/name.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iterator.from
description: >
The "name" property of Iterator.from
info: |
17 ECMAScript Standard Built-in Objects

Every built-in Function object, including constructors, that is not
identified as an anonymous function has a name property whose value is a
String. Unless otherwise specified, this value is the name that is given to
the function in this specification.

...

Unless otherwise specified, the name property of a built-in Function
object, if it exists, has the attributes { [[Writable]]: false,
[[Enumerable]]: false, [[Configurable]]: true }.
features: [iterator-helpers]
includes: [propertyHelper.js]
---*/

verifyProperty(Iterator.from, 'name', {
value: 'from',
writable: false,
enumerable: false,
configurable: true,
});
23 changes: 23 additions & 0 deletions test/built-ins/Iterator/from/non-constructible.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iterator.from
description: >
Iterator.from is not constructible.

Built-in function objects that are not identified as constructors do not implement the [[Construct]] internal method unless otherwise specified in the description of a particular function.
features: [iterator-helpers]
---*/
function* g() {}

assert.throws(TypeError, () => {
new Iterator.from();
});

assert.throws(TypeError, () => {
new Iterator.from(g());
});

assert.throws(TypeError, () => {
new class extends Iterator {}.from(g());
});
38 changes: 38 additions & 0 deletions test/built-ins/Iterator/from/primitives.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright (C) 2023 Michael Ficarra. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iterator.from
description: >
Iterator.from throws on primitives (except Strings)
info: |
Iterator.from ( O )

features: [iterator-helpers]
flags: []
---*/

assert.throws(TypeError, function () {
Iterator.from(null);
});

assert.throws(TypeError, function () {
Iterator.from(undefined);
});

assert.throws(TypeError, function () {
Iterator.from(0);
});

assert.throws(TypeError, function () {
Iterator.from(0n);
});

assert.throws(TypeError, function () {
Iterator.from(true);
});

assert.throws(TypeError, function () {
Iterator.from(Symbol());
});

Iterator.from('string');
26 changes: 26 additions & 0 deletions test/built-ins/Iterator/from/prop-desc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iterator.from
description: >
Property descriptor of Iterator.from
info: |
Iterator.from

* is the initial value of the Iterator.from property of the global object.

17 ECMAScript Standard Built-in Objects

Every other data property described in clauses 18 through 26 and in Annex B.2
has the attributes { [[Writable]]: true, [[Enumerable]]: false,
[[Configurable]]: true } unless otherwise specified.
features: [globalThis, iterator-helpers]
includes: [propertyHelper.js]
---*/

verifyProperty(Iterator, 'from', {
value: Iterator.from,
writable: true,
enumerable: false,
configurable: true,
});
15 changes: 15 additions & 0 deletions test/built-ins/Iterator/from/proto.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-iterator.from
description: >
The value of the [[Prototype]] internal slot of Iterator.from is the
intrinsic object %FunctionPrototype%.
features: [iterator-helpers]
---*/

assert.sameValue(
Object.getPrototypeOf(Iterator.from),
Function.prototype,
'Object.getPrototypeOf(Iterator.from) must return the value of Function.prototype'
);
Loading