Skip to content

Commit

Permalink
Update DummyArrayIteratorPrototype
Browse files Browse the repository at this point in the history
  • Loading branch information
petamoriken committed Jan 8, 2022
1 parent 1146765 commit 7d27b1c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
20 changes: 14 additions & 6 deletions src/_util/arrayIterator.mjs
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import {
ArrayIteratorPrototype,
ArrayIteratorPrototypeNext,
ArrayPrototypeSymbolIterator,
GeneratorPrototypeNext,
IteratorPrototype,
NativeArrayPrototypeSymbolIterator,
NativeWeakMap,
ObjectCreate,
ObjectDefineProperty,
ReflectGetOwnPropertyDescriptor,
ReflectOwnKeys,
SymbolIterator,
SymbolToStringTag,
WeakMapPrototypeGet,
WeakMapPrototypeSet,
} from "./primordials.mjs";
Expand Down Expand Up @@ -51,13 +54,18 @@ const DummyArrayIteratorPrototype = ObjectCreate(IteratorPrototype, {
writable: true,
configurable: true,
},

[SymbolToStringTag]: {
value: "Array Iterator",
configurable: true,
},
});

for (const key of ReflectOwnKeys(ArrayIteratorPrototype)) {
// next method has already defined
if (key === "next") {
continue;
}

// Copy ArrayIteratorPrototype descriptors to DummyArrayIteratorPrototype
ObjectDefineProperty(DummyArrayIteratorPrototype, key, ReflectGetOwnPropertyDescriptor(ArrayIteratorPrototype, key));
}

/** @type {<T>(generator: Generator<T>) => IterableIterator<T>} */
export function wrapGenerator(generator) {
const dummy = ObjectCreate(DummyArrayIteratorPrototype);
Expand Down
2 changes: 1 addition & 1 deletion src/_util/primordials.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export const NativeFloat32Array = Float32Array;

// ArrayIterator
/** @type {any} */
const ArrayIteratorPrototype = ReflectGetPrototypeOf([][SymbolIterator]());
export const ArrayIteratorPrototype = ReflectGetPrototypeOf([][SymbolIterator]());
/** @type {<T>(arrayIterator: IterableIterator<T>) => IteratorResult<T>} */
export const ArrayIteratorPrototypeNext = uncurryThis(ArrayIteratorPrototype.next);

Expand Down

0 comments on commit 7d27b1c

Please sign in to comment.