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

Property alias on a javascript object points to different and corrupted object

XMLWordPrintable

    • 3dbe05f6bf3fd51ce8097c35f6c7f12b39acb0f6 (qtdeclarative)

      A property alias on a JavaScript object does not point to the same object. In fact, it points to an object of which the functions have been turned into objects that cannot be invoked.
      This also happens when you assign a JavaScript object to an alias, in which case both the alias and the aliased property have their functions turned into non-invokable objects.

      Here is a test to illustrate the problem (with working code for an alias on a QML item for comparison):

      import QtQuick 2.3
      import QtTest 1.0
      
      Item {
          QtObject {
              id: myObject
              property var item: Item {}
              property alias itemAlias : myObject.item
      
              property var jsObject: ({ myFunction: function(x,y) {} })
              property alias jsObjectAlias : myObject.jsObject
          }
      
          TestCase {
      
              function test_itemAlias() {
                  // this works
                  compare(myObject.itemAlias, myObject.item);
                  compare(typeof(myObject.itemAlias.childAt), typeof(myObject.item.childAt));
              }
      
              function test_jsObjectAlias() {
                  // the following comparison fails
                  compare(myObject.jsObjectAlias, myObject.jsObject);
                  // the following comparison also fails (actual: object; expected: function)
                  compare(typeof(myObject.jsObjectAlias.myFunction), typeof(myObject.jsObject.myFunction));
              }
      
              function test_jsObjectAliasAssignment() {
                  var myJsObject = { myOtherFunction: function(x,y) {} };
                  myObject.jsObjectAlias = myJsObject;
                  // the following comparisons fails
                  compare(myObject.jsObject, myJsObject);
                  compare(myObject.jsObjectAlias, myJsObject);
                  // the following comparisons also fails (actual: object; expected: function)
                  compare(typeof(myObject.jsObject.myOtherFunction), typeof(myJsObject.myOtherFunction));
                  compare(typeof(myObject.jsObjectAlias.myOtherFunction), typeof(myJsObject.myOtherFunction));
              }
          }
      }
      

        1. qtquick-test.zip
          4 kB
          Mitch Curtis
        For Gerrit Dashboard: QTBUG-40431
        # Subject Branch Project Status CR V

            shausman Simon Hausmann
            che Carsten Henßinger
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes