1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 11:38:11 +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:
Matthew Olsson 2020-07-13 08:27:20 -07:00 committed by Andreas Kling
parent 4970c448bf
commit a51b2393f2
8 changed files with 187 additions and 127 deletions

View file

@ -91,3 +91,22 @@ test("spreading non-spreadable values", () => {
};
expect(Object.getOwnPropertyNames(empty)).toHaveLength(0);
});
test("respects custom Symbol.iterator method", () => {
let o = {
[Symbol.iterator]() {
return {
i: 0,
next() {
if (this.i++ == 3) {
return { done: true };
}
return { value: this.i, done: false };
},
};
},
};
let a = [...o];
expect(a).toEqual([1, 2, 3]);
});