Skip to content

runtime: class M extends Map {} / extends Set — instance has no methods at all (m.set(...) throws TypeError) #6325

Description

@proggeramlug

Summary

class M extends Map {} produces an instance with no Map methods at all. Calling any of them throws. Same for Set. This is not an override-ordering problem — subclassing these builtins is simply broken, with no override involved.

Confirmed on clean origin/main.

Repro

class M extends Map {}
const m = new M();
m.set("a", 1);
console.log("map subclass get:", m.get("a"), "size:", m.size);
output
node 26 map subclass get: 1 size: 1
perry main TypeError: set is not a function

Set behaves the same way.

Context

Surfaced while fixing #6316 (subclass method overriding a native base method was silently bypassed). During that work an affected-base matrix was measured:

base override runs? super.<m>() reaches base?
EventEmitter fixed in #6322 fixed in #6322
node:stream (Readable/Writable/…) fixed in #6322 fixed in #6322
EventTarget fixed in #6301 / #6311
Array yes nosuper.push() no-ops
Error yes nosuper.toString()undefined
Promise yes nosuper.then not a function
Map / Set n/a — subclassing itself is broken no

So Map/Set are the worst case in that table: the earlier-reported super failure for them is a symptom of the instance having no methods at all, not of dispatch ordering.

Related: #6316 (override bypass, fixed in #6322), #6301 (extends EventTarget, fixed in #6311). Note #6232/#6260 added class X extends Array support — Map/Set appear to have never gotten the equivalent.

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