Skip to content

feat(resolver): resolve this-dispatch inside Object.defineProperty accessor functions (JS) #1335

@carlos-alm

Description

@carlos-alm

Pattern

When a function is registered as a getter or setter via `Object.defineProperty`, `this` inside that function refers to the object the property was defined on. Codegraph does not resolve `this.method()` calls inside such accessors.

Failing example (from Jelly micro-test `accessors3.js`)

```js
const obj = {
baz: () => { console.log("baz"); },
};

function getter() {
this.baz(); // this === obj when invoked as obj's accessor
}

Object.defineProperty(obj, "bar", { get: getter });

const x = obj.bar; // invokes getter, which calls obj.baz
```

Expected edge: `getter → baz` (via `this.baz()` with `this === obj`) — not resolved.

Relationship to #1320

Issue #1320 tracks resolving calls to functions installed via `Object.defineProperty` (i.e. the getter/setter themselves as callees). This issue is distinct: it's about `this`-dispatch inside accessor functions once they are called — knowing that `this` is bound to the descriptor's target object.

What's needed

  1. Track that `getter` is used as a `get`/`set` descriptor for `obj` (via `Object.defineProperty`)
  2. When resolving `this.baz()` inside `getter`, use `obj` as the receiver type

Benchmark evidence

Jelly micro-test corpus (`tests/benchmarks/resolution/fixtures/jelly-micro/accessors3/`):

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    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