Closed Bug 1002010 Opened 11 years ago Closed 11 years ago

Subclassing Map fails

Categories

(Core :: JavaScript Engine, defect)

defect
Not set
normal

Tracking

()

RESOLVED DUPLICATE of bug 838540

People

(Reporter: aleth, Unassigned)

Details

If one tries to subclass a Map using Object.create, one runs into the following problem: function newMap(args) { Map.call(this, args); } newMap.prototype = Object.create(Map.prototype); newMap.prototype.constructor = newMap; let testmap = new newMap([["a",1],["b",2]]); print(testmap.get("b")); /* Exception: get method called on incompatible Object */ This despite newMaps being instances of Maps. It's possible this is in fact not a bug, but if so, I'd like to understand why (and it probably should be explained on MDN too).
SpiderMonkey doesn't have ES6 subclassing support (and in particular support for @@create) yet. So "this" in newMap ends up as a plain Object without the internal slots a Map needs.
Status: NEW → RESOLVED
Closed: 11 years ago
Resolution: --- → DUPLICATE
You need to log in before you can comment on or make changes to this bug.