Skip to content

Relinked class prototype: instanceof, typeof super.m and the __proto__ setter still use the declared chain #11765

Description

@proggeramlug

These are still wrong after #11764 (which fixes member reads, in, calls and super.m() after Object.setPrototypeOf(C.prototype, X)):

class B { m() { return 1; } }
class C extends B { t() { return typeof super.m; } }
const inst = new C();
Object.setPrototypeOf(C.prototype, { k: 7 });
console.log(inst instanceof B);   // node: false   perry: true
console.log(inst.t());            // node: undefined   perry: function

class D extends B {}
(D.prototype as any).__proto__ = { k: 7 };
console.log(Object.getPrototypeOf(D.prototype) === B.prototype);   // node: false   perry: true (no relink happens)
  • instanceof: goes through class_chain_reaches, whose ~20 callers all walk the declared parent chain (get_parent_class_id). It should walk the instance's live [[Prototype]] chain when a class prototype on the way was relinked.
  • typeof super.m / super property reads: resolved at compile time. A guarded runtime fallback needs the home class id, which no existing runtime entry point takes.
  • C.prototype.__proto__ = X: the __proto__ setter on a class prototype doesn't relink at all, on main or with Drop the old parent's members from a relinked class chain #11764.

Related: #11760 (super.m() ignores a patched parent prototype without a relink).

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions