Skip to content

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

Closed

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

Activity

  1. saghul commented on Jul 3, 2026

    @saghul
    Contributor

    Fix in #1558

  2. added a commit that references this issue on Jul 6, 2026
    4b7e920
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions