mirror of
https://github.com/RGBCube/serenity
synced 2025-05-20 18:15:07 +00:00
LibJS: Integrate iterator protocol into language features
Finally use Symbol.iterator protocol in language features :) currently only used in for-of loops and spread expressions, but will have more uses later (Maps, Sets, Array.from, etc).
This commit is contained in:
parent
4970c448bf
commit
a51b2393f2
8 changed files with 187 additions and 127 deletions
|
@ -13,6 +13,24 @@ test("basic functionality", () => {
|
|||
expect(foo(..."abc")).toBe("c");
|
||||
});
|
||||
|
||||
test("spreading custom iterable", () => {
|
||||
let o = {
|
||||
[Symbol.iterator]() {
|
||||
return {
|
||||
i: 0,
|
||||
next() {
|
||||
if (this.i++ === 3) {
|
||||
return { done: true };
|
||||
}
|
||||
return { value: this.i };
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
expect(Math.max(...o)).toBe(3);
|
||||
});
|
||||
|
||||
test("spreading non iterable", () => {
|
||||
expect(() => {
|
||||
[...1];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue