Skip to content

runtime: make Reflect.getPrototypeOf return the actual prototype #2757

Description

@andrewtdiz

Summary

Perry's Reflect.getPrototypeOf helper returns the input object itself. Node returns the object's actual prototype, including null for null-prototype objects and the target/proxy prototype chain for ordinary objects.

Node behavior

On Node v25.9.0:

Reflect.getPrototypeOf({}) === Object.prototype; // true

const proto = { p: 1 };
const made = Object.create(proto);
Reflect.getPrototypeOf(made) === proto; // true

class Base {}
class Child extends Base {}
Reflect.getPrototypeOf(Child.prototype) === Base.prototype; // true

Reflect.getPrototypeOf(Object.create(null)); // null

Perry evidence

Current origin/main routes Reflect.getPrototypeOf(...) through a separate Reflect helper:

  • crates/perry-hir/src/lower/expr_call/native_module.rs lowers Reflect getPrototypeOf calls to Expr::ReflectGetPrototypeOf(...).
  • crates/perry-codegen/src/expr/proxy_reflect.rs lowers that HIR node to js_reflect_get_prototype_of(...).
  • crates/perry-runtime/src/proxy.rs::js_reflect_get_prototype_of() is implemented as return obj, and the comment says it returns the object itself.

That means generic Reflect.getPrototypeOf(obj) sites can observe obj instead of the prototype, even though Object.getPrototypeOf has separate prototype-chain logic elsewhere.

Expected fix

Reflect.getPrototypeOf(target) should share the same actual prototype lookup semantics as Object.getPrototypeOf(target) and return null for null-prototype objects. It should not return the target object itself.

Scope note: this is distinct from prior Object.getPrototypeOf fixes such as PR #2050, #2196, and #2244. This issue is specifically the remaining Reflect.getPrototypeOf helper path.

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