-
Bug
-
Resolution: Fixed
-
Minor
-
2.9.5, 3.0.3
-
MOODLE_29_STABLE, MOODLE_30_STABLE
-
MOODLE_29_STABLE, MOODLE_30_STABLE
-
Throughout moodle-block_navigation-navigation.js for-in constructs are used to iterate over 'simple' Arrays. The problem is that if other code has extended the Array type (i.e. Array.prototype.somefunction) the loop will also try to iterate over these additional methods as if they were properties. This results in exceptions and a YUI popup window with "System Error" when clicking to expand "Site administration"
I found an unresolved issue here https://tracker.moodle.org/browse/MDL-37388 and some background info on why using for-in to iterate over an Array is often not a good idea here http://stackoverflow.com/questions/500504/why-is-using-for-in-with-array-iteration-such-a-bad-idea.
The problem in my case pops up because I am using an external reporting tool (jchartfx.com) that actually extends the Array prototype.
There are various easy fixes possible. It would probably be best (at least in the cases I have seen in this code) to replace the for-in loop by using a simple for-loop with an enumerator. There are some cases where you would want to use a for-in loop but you'd still have to make sure you use only the properties that were intended, e.g. by checking hasOwnProperty
- has a non-specific relationship to
-
MDL-37388 Bad array looping in autolink.js from glossary filter.
-
- Closed
-