Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-71138

Extending built-in classes not working properly

    XMLWordPrintable

Details

    • 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+.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            laknoll Lars Knoll
            evg656e Evgeny
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes