X-Git-Url: https://git.ladys.computer/Pisces/blobdiff_plain/683480a2a3dcf9f9a7585b0e9fd98f431ff1c9fa..refs/heads/current:/iterable.js?ds=sidebyside diff --git a/iterable.js b/iterable.js index 2eb9aa4..7149a28 100644 --- a/iterable.js +++ b/iterable.js @@ -9,11 +9,13 @@ import { bind, call, identity } from "./function.js"; import { + defineOwnDataProperty, defineOwnProperty, getPrototype, objectCreate, + setPropertyValues, } from "./object.js"; -import { ITERATOR, TO_STRING_TAG } from "./value.js"; +import { ITERATOR, TO_STRING_TAG, UNDEFINED } from "./value.js"; export const { /** @@ -228,7 +230,7 @@ export const { const nextIterator = this.#nextIterator; if (baseIterator === null) { // The base iterator has already been exhausted. - return { value: undefined, done: true }; + return { value: UNDEFINED, done: true }; } else if (nextIterator === null) { // This iterator is not currently yielding values from the // provided generator function, either because it doesn’t @@ -296,20 +298,20 @@ export const { objectCreate( iteratorPrototype, { - next: { + next: setPropertyValues(objectCreate(null), { configurable: true, enumerable: false, value: function next() { return call(iteratorNext, this, []); }, writable: true, - }, - [TO_STRING_TAG]: { + }), + [TO_STRING_TAG]: setPropertyValues(objectCreate(null), { configurable: true, enumerable: false, value: stringTag, writable: false, - }, + }), }, ); @@ -330,7 +332,7 @@ export const { stringTag = "Iterator", ) => { const prototype = makePrototype(stringTag); // intentionally cached - return ($, thisArg = undefined) => + return ($, thisArg = UNDEFINED) => new Iterator( prototype, call(makeBaseIterator, $, []), @@ -343,16 +345,20 @@ export const { arrayIteratorFunction: defineOwnProperty( bind( iteratorFunction, - undefined, + UNDEFINED, [arrayIterator, arrayIteratorNext], ), "name", - { value: "arrayIteratorFunction" }, + defineOwnDataProperty( + objectCreate(null), + "value", + "arrayIteratorFunction", + ), ), generatorIteratorFunction: defineOwnProperty( bind( iteratorFunction, - undefined, + UNDEFINED, [ function () { return this(); @@ -361,34 +367,50 @@ export const { ], ), "name", - { value: "generatorIteratorFunction" }, + defineOwnDataProperty( + objectCreate(null), + "value", + "generatorIteratorFunction", + ), ), mapIteratorFunction: defineOwnProperty( bind( iteratorFunction, - undefined, + UNDEFINED, [mapIterator, mapIteratorNext], ), "name", - { value: "mapIteratorFunction" }, + defineOwnDataProperty( + objectCreate(null), + "value", + "mapIteratorFunction", + ), ), setIteratorFunction: defineOwnProperty( bind( iteratorFunction, - undefined, + UNDEFINED, [setIterator, setIteratorNext], ), "name", - { value: "setIteratorFunction" }, + defineOwnDataProperty( + objectCreate(null), + "value", + "setIteratorFunction", + ), ), stringIteratorFunction: defineOwnProperty( bind( iteratorFunction, - undefined, + UNDEFINED, [stringIterator, stringIteratorNext], ), "name", - { value: "stringIteratorFunction" }, + defineOwnDataProperty( + objectCreate(null), + "value", + "stringIteratorFunction", + ), ), }; })();