Skip to content

class [Symbol.iterator] methods: super[Symbol.iterator]() recurses; delete C.prototype[Symbol.iterator] is a no-op #11698

Description

@proggeramlug

Found while fixing #11692 (PR #11697). Both reproduce on pristine main 6a50907 and are unrelated to that fix.

  1. super[Symbol.iterator]() recurses until the stack overflows
class B { *[Symbol.iterator]() { yield 1; yield 2; } }
class D extends B { [Symbol.iterator]() { return super[Symbol.iterator](); } }
console.log([...new D()]); // node: [ 1, 2 ]; perry: stack overflow
  1. delete C.prototype[Symbol.iterator] doesn't remove the method
class C { *[Symbol.iterator]() { yield 1; } }
delete (C.prototype as any)[Symbol.iterator];
console.log(Symbol.iterator in new C()); // node: false; perry: true

Likely cause: symbol-keyed class methods are dispatched under internal names (@@iterator) and stored under the symbol key. super lookup and delete don't resolve that mapping the same way the call path does.

Activity

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

    bugConfirmed defect or regression

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions