Skip to content

[BUG] Chained filter().take(1).toArray() throws TypeError: not a function #1557

Description

@kid-lxy

A valid Iterator Helpers chain using filter(), take(), and toArray() unexpectedly throws:

TypeError: not a function
    at return (native)
    at toArray (native)
    at <eval> (tools/quickjs_verify/iterator_chain_no_return.js:6:82)

The iterator should produce a one-element array instead.
The failure appears to occur when take(1) reaches its limit and attempts to close the iterator helper returned by filter().

Save the following as iterator_take_bug.js:

var result = Iterator.from([1, 2, 3, 4])
    .filter(function (x) {
        return x > 1;
    })
    .take(1)
    .toArray();

print(JSON.stringify(result));

Run it using the QuickJS command-line interpreter:

./qjs iterator_take_bug.js

QuickJS version

QuickJS version/release: v0.15.1
Git commit: 93d3f7d
Operating system: Ubuntu 24.04 x86_64

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions