Skip to content

this is undefined inside a do…while body in non-class functions (breaks node-forge rsa_sign) #11724

Description

@proggeramlug

Found by the package matrix re-run (#11723): node-forge/rsa_sign throws TypeError: … (reading 'data'). Reproduces 3/3 at 9e29f59 and on origin/main 9e05951.

Inside a do…while body, this is undefined in any non-class function. A plain while loop works, and so does a class method.

const o = { d: 7, f(n) { let r = 0; do { r += this.d; n--; } while (n > 0); return r; } };
console.log(o.f(1)); // node: 7; perry: throws TypeError

Activity

  1. proggeramlug commented on Oct 1, 2026

    @proggeramlug
    ContributorAuthor

    Hint for whoever picks this up: a fix attempt that was stopped part-way traced it to two separate statement walkers that don't handle do…while bodies the same way (likely the this/captures analysis after #11637 made this a body parameter). The planned fix was to replace both walkers with one exhaustive helper, so no statement kind can be missed. Please also check for/for-in/for-of/labeled loops/continue paths, and arguments/new.target inside do-while. Acceptance: the repro matches Node, and node-forge/rsa_sign passes (scripts/package_bench.py, benchmarks/packages).

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