Details
-
Suggestion
-
Resolution: Unresolved
-
Not Evaluated
-
None
-
6.3.2
-
None
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.