Details
-
Bug
-
Resolution: Done
-
P2: Important
-
5.12.0 Beta 1, 5.12
-
None
-
33c13efd91954fb50019e82f3ab8e8e1d8458332 (qt/qtdeclarative/5.12)
Description
Extending built-in classes fails with user defined methods. When no user-defined methods are called, everything works fine though.
class Style extends Map { constructor(attrs) { super(); // throws TypeError: Type error this.reset(attrs); } reset(attrs) { this.clear(); Object.keys(attrs).forEach(name => { this.set(name, attrs[name]); }); } } class Items extends Array { constructor(items) { super(); // throws TypeError: Type error this.reset(items); } reset(items) { this.length = 0; if (items) this.push(...items); } } function testStyle() { const style = new Style({ 'strokeStyle': 'black', 'lineWidth': 2 }); // ok // style.set('strokeStyle', 'black'); // style.set('lineWidth', 2); // throws TypeError: Type error style.reset({ 'strokeStyle': 'black', 'lineWidth': 2 }); console.log(JSON.stringify([...style.entries()])); } function testItems() { const items = new Items([1, 2, 3]); // ok // items.push([1, 2, 3]); // throws TypeError: Type error items.reset([1, 2, 3]); console.log(JSON.stringify([...items])); } export function main() { testItems(); testStyle(); }
According to specs code above should work in es6+.