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:
parent
4970c448bf
commit
a51b2393f2
8 changed files with 187 additions and 127 deletions
|
@ -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]);
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue