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 |
no — super.push() no-ops |
Error |
yes |
no — super.toString() → undefined |
Promise |
yes |
no — super.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.
Summary
class M extends Map {}produces an instance with no Map methods at all. Calling any of them throws. Same forSet. This is not an override-ordering problem — subclassing these builtins is simply broken, with no override involved.Confirmed on clean
origin/main.Repro
map subclass get: 1 size: 1mainTypeError: set is not a functionSetbehaves 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:
super.<m>()reaches base?EventEmitternode:stream(Readable/Writable/…)EventTargetArraysuper.push()no-opsErrorsuper.toString()→undefinedPromisesuper.thennot a functionMap/SetSo
Map/Setare the worst case in that table: the earlier-reportedsuperfailure 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 addedclass X extends Arraysupport —Map/Setappear to have never gotten the equivalent.