Closed
Description
Version
24.1.0, 24.0.2, 22.16.0
Platform
Darwin Kernel Version 24.5.0: Tue Apr 22 19:54:49 PDT 2025; root:xnu-11417.121.6~2/RELEASE_ARM64_T6000 arm64
Subsystem
No response
What steps will reproduce the bug?
function* fibonacci() {
let current = 1;
let next = 1;
while (true) {
yield current;
[current, next] = [next, current + next];
}
}
// Correct output
const fibGen = fibonacci();
let iter1 = fibGen.take(3);
console.log(iter1.next().value); // 1
console.log(iter1.next().value); // 1
console.log(iter1.next().value); // 2
iter1 = fibGen.take(3);
console.log(iter1.next().value); // 3
console.log(iter1.next().value); // 5
console.log(iter1.next().value); // 8
// Incorrect output?
const fibGen2 = fibonacci();
let iter2 = fibGen2.take(3);
let takeToArray = Array.from(iter2);
console.log(takeToArray); // Outputs [1, 1, 2]
iter2 = fibGen2.take(3);
takeToArray = Array.from(iter2);
console.log(takeToArray); // Output: [] Expected: [3,5,8]
How often does it reproduce? Is there a required condition?
Consistently reproduced with above example code
What is the expected behavior? Why is that the expected behavior?
Expecting the next take(n) on the generator to return all values up to max take parameter (n) and Array.from() to correctly return generated values
What do you see instead?
empty array ([])
Additional information
Thank you for all the work the team does :)
I am not sure if I am using Iterator.prototype.take correctly, I have read the documentation at [mdn web docs] (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator/take#using_take) and think I am using it correctly.
Apologies I cannot implement a fix, I am not proficient in C++ or the nodejs project.
I would gladly contribute if someone could give me some direction!
Thank you for your time.
Metadata
Metadata
Assignees
Labels
No labels