Skip to content

Commit

Permalink
https://github.com/tc39/proposal-iterator-helpers/pull/272
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelficarra committed May 22, 2023
1 parent 1725372 commit 66af382
Showing 1 changed file with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/*---
esid: sec-iteratorprototype.flatMap
description: >
Iterator.prototype.flatMap falls back to treating mapper return values as iterators if the Symbol.iterator property is not callable
Iterator.prototype.flatMap falls back to treating mapper return values as iterators if the Symbol.iterator property is null/undefined
info: |
%Iterator.prototype%.flatMap ( mapper )
Expand Down Expand Up @@ -32,4 +32,26 @@ let iter = g().flatMap(v => {
};
});

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

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

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

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

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

0 comments on commit 66af382

Please sign in to comment.