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:
parent
acd8c94e88
commit
ff4e0d2943
5 changed files with 39 additions and 18 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue