Not using 'var' keyword in Javascript for loop inside recursive function causes infinite loop
Categories
(Firefox :: Untriaged, defect)
Tracking
()
People
(Reporter: ggrantward, Unassigned, NeedInfo)
Details
User Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0
Steps to reproduce:
function recurse(someValue) {
if (someValue) {
for (i=0; i<5; i++) {
recurse(someAction(someValue));
}
}
}
Actual results:
Infinite loop that was not stoppable and crashed my computer
Expected results:
variable i should have been local to the function and isolated from subsequent calls, however it was overwritten by each subsequent recursion
| Reporter | ||
Comment 1•5 years ago
|
||
The code example is wrong. The loop will not occur with a set value as in i<5, it will only happen in a dynamic case such as element.children.length.
Comment 2•5 years ago
|
||
Hi,
Since the example is wrong, could you attach another example, like done in bug#1694740? Or upload the code to any other platform and share it with us, please.
Thanks, Flor.
Updated•5 years ago
|
Hi ggrantward,
Are you still experiencing the issue?
In the mean time I'll mark this as Resolved-Incomplete due to lack of information. If the issue is still reproducible with the latest Firefox version, please feel free to reopen the bug with more information (such as steps to reproduce, or sample test page).
Thanks in advance,
Virginia
Description
•