1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 19:07:34 +00:00

LibJS: Avoid creating String object wrappers in iterator helpers

This is a normative change in the Iterator Helpers spec. See:
3e275cf
This commit is contained in:
Timothy Flynn 2023-07-12 15:45:05 -04:00 committed by Linus Groh
parent acd8c94e88
commit ff4e0d2943
5 changed files with 39 additions and 18 deletions

View file

@ -60,6 +60,22 @@ describe("normal behavior", () => {
expect(result.done).toBeTrue();
});
test("does not coerce strings to objects", () => {
const stringIterator = String.prototype[Symbol.iterator];
let observedType = null;
Object.defineProperty(String.prototype, Symbol.iterator, {
get() {
"use strict";
observedType = typeof this;
return stringIterator;
},
});
Iterator.from("ab");
expect(observedType).toBe("string");
});
test("create Iterator from generator", () => {
function* generator() {
yield 1;