From: Lady Date: Sat, 21 Oct 2023 19:47:08 +0000 (-0400) Subject: Test constructability, name, length in iterable.js X-Git-Url: https://git.ladys.computer/Pisces/commitdiff_plain/683480a2a3dcf9f9a7585b0e9fd98f431ff1c9fa?ds=sidebyside;hp=8bf43f6e1898ca921d5e63b4513e4c6b2241ebc5 Test constructability, name, length in iterable.js --- diff --git a/iterable.js b/iterable.js index d89e35f..2eb9aa4 100644 --- a/iterable.js +++ b/iterable.js @@ -326,7 +326,7 @@ export const { const iteratorFunction = ( makeBaseIterator, baseIteratorNext, - generateNext = null, + generateNext, stringTag = "Iterator", ) => { const prototype = makePrototype(stringTag); // intentionally cached @@ -335,7 +335,7 @@ export const { prototype, call(makeBaseIterator, $, []), baseIteratorNext, - generateNext === null ? null : bind(generateNext, thisArg, []), + generateNext == null ? null : bind(generateNext, thisArg, []), ); }; diff --git a/iterable.test.js b/iterable.test.js index 2e62d5c..0f7c9fc 100644 --- a/iterable.test.js +++ b/iterable.test.js @@ -34,6 +34,25 @@ describe("arrayIteratorFunction", () => { ); }); + it("[[Construct]] throws an error", () => { + assertThrows(() => new arrayIteratorFunction()); + }); + + describe(".length", () => { + it("[[Get]] returns the correct length", () => { + assertStrictEquals(arrayIteratorFunction.length, 1); + }); + }); + + describe(".name", () => { + it("[[Get]] returns the correct name", () => { + assertStrictEquals( + arrayIteratorFunction.name, + "arrayIteratorFunction", + ); + }); + }); + describe("()", () => { it("[[Call]] returns a value which inherits from %IteratorPrototype%", () => { const iteratorProto = Object.getPrototypeOf( @@ -130,6 +149,25 @@ describe("generatorIteratorFunction", () => { ); }); + it("[[Construct]] throws an error", () => { + assertThrows(() => new generatorIteratorFunction()); + }); + + describe(".length", () => { + it("[[Get]] returns the correct length", () => { + assertStrictEquals(generatorIteratorFunction.length, 1); + }); + }); + + describe(".name", () => { + it("[[Get]] returns the correct name", () => { + assertStrictEquals( + generatorIteratorFunction.name, + "generatorIteratorFunction", + ); + }); + }); + describe("()", () => { it("[[Call]] returns a value which inherits from %IteratorPrototype%", () => { const iteratorProto = Object.getPrototypeOf( @@ -248,6 +286,25 @@ describe("mapIteratorFunction", () => { ); }); + it("[[Construct]] throws an error", () => { + assertThrows(() => new mapIteratorFunction()); + }); + + describe(".length", () => { + it("[[Get]] returns the correct length", () => { + assertStrictEquals(mapIteratorFunction.length, 1); + }); + }); + + describe(".name", () => { + it("[[Get]] returns the correct name", () => { + assertStrictEquals( + mapIteratorFunction.name, + "mapIteratorFunction", + ); + }); + }); + describe("()", () => { it("[[Call]] returns a value which inherits from %IteratorPrototype%", () => { const iteratorProto = Object.getPrototypeOf( @@ -344,6 +401,25 @@ describe("setIteratorFunction", () => { ); }); + it("[[Construct]] throws an error", () => { + assertThrows(() => new setIteratorFunction()); + }); + + describe(".length", () => { + it("[[Get]] returns the correct length", () => { + assertStrictEquals(setIteratorFunction.length, 1); + }); + }); + + describe(".name", () => { + it("[[Get]] returns the correct name", () => { + assertStrictEquals( + setIteratorFunction.name, + "setIteratorFunction", + ); + }); + }); + describe("()", () => { it("[[Call]] returns a value which inherits from %IteratorPrototype%", () => { const iteratorProto = Object.getPrototypeOf( @@ -440,6 +516,25 @@ describe("stringIteratorFunction", () => { ); }); + it("[[Construct]] throws an error", () => { + assertThrows(() => new stringIteratorFunction()); + }); + + describe(".length", () => { + it("[[Get]] returns the correct length", () => { + assertStrictEquals(stringIteratorFunction.length, 1); + }); + }); + + describe(".name", () => { + it("[[Get]] returns the correct name", () => { + assertStrictEquals( + stringIteratorFunction.name, + "stringIteratorFunction", + ); + }); + }); + describe("()", () => { it("[[Call]] returns a value which inherits from %IteratorPrototype%", () => { const iteratorProto = Object.getPrototypeOf(