Skip to content

runtime: class X extends EventTarget doesn't inherit addEventListener/dispatchEvent (root cause of #5931, breaks cac) #6301

Description

@proggeramlug

Summary

class X extends EventTarget does not inherit addEventListener / removeEventListener / dispatchEvent. The subclass instance reports them as undefined, and calling one throws TypeError: value is not a function.

Repro

class Bus extends EventTarget {}
const b = new Bus();
console.log("typeof dispatchEvent:", typeof b.dispatchEvent);
console.log("typeof addEventListener:", typeof b.addEventListener);
output
node 26 function / function
perry main @ 0960415 undefined / undefined

Verified on a clean origin/main build.

Root cause (suspected)

EventTarget appears to be implemented as name-keyed native method dispatch (crates/perry-runtime/src/event_target.rs, registered in object/global_this_tables.rs) rather than as real function properties resident on a prototype object. The telling detail: on a plain new EventTarget(), t.addEventListener(...) works as a call (the listener fires) but typeof t.addEventListener is still undefined. Because there is nothing on the prototype, a subclass inherits nothing.

class A extends EventTarget {}; class B extends A {} is also undefined.

Likely the same shape as the prototype work in #6147/#6148/#6149: the methods need to live on a real prototype object rather than being resolved by receiver name.

Impact

This breaks any package whose class extends EventTarget. It is the actual root cause of #5931 ("Using cac with default command resulting in error"): cac v7's CAC class is class CAC extends EventTarget, and every matched command path calls this.dispatchEvent(...), so any matching command dies with TypeError: value is not a function. (#5931's title is misleading — it is not about the default command; a command with no .action() fails too.)

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