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

qmltest/TestCase.qml forbids extensions of JS Array prototype

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Unresolved
    • Not Evaluated
    • None
    • 6.3.2
    • Testing: QuickTest
    • None
    • All

    Description

      TestCase.qml file iterates over an array of tests using this construct:

       

      for (var index in testList) {
      }

      This should not be done as the above will also enumerate any custom additions to Array.prototype and end up hanging the test harness due to subsequent QML errors.

       

      There is a nice rationale of why the above construct should be avoided here:

      https://stackoverflow.com/questions/3010840/loop-through-an-array-in-javascript

      Citing:

      Do not use for...in

      @zipcodeman suggests the use of the for...in statement, but for iterating arrays for-in should be avoided, that statement is meant to enumerate object properties.

      It shouldn't be used for array-like objects because:

      • The order of iteration is not guaranteed; the array indexes may not be visited in numeric order.
      • Inherited properties are also enumerated.

      The second point is that it can give you a lot of problems, for example, if you extend the Array.prototype object to include a method there, that property will also be enumerated.

       

      Attachments

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

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            dariusz.maciejewski Dariusz Maciejewski
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes