Closed Bug 519737 Opened 15 years ago Closed 14 years ago

Javascript: pre/post incrementing a variable as an argument to eval sometimes results in incrementing by 2

Categories

(Firefox :: General, defect)

x86_64
Linux
defect
Not set
normal

Tracking

()

RESOLVED INCOMPLETE

People

(Reporter: theburkeyuk, Unassigned)

Details

(Whiteboard: [CLOSEME 2010-12-01])

User-Agent:       Mozilla/5.0 (X11; U; Linux x86_64; en-GB; rv:1.9.0.12) Gecko/2009070818 Ubuntu/8.10 (intrepid) Firefox/3.0.12
Build Identifier: Mozilla/5.0 (X11; U; Linux x86_64; en-GB; rv:1.9.0.12) Gecko/2009070818 Ubuntu/8.10 (intrepid) Firefox/3.0.12

Incrementing a variable as an argument to eval sometimes results in incrementing by 2.

I had the problem with a larger webapp while using a library called overLIB but I narrowed it down to this small test case script:

    var k = 5;
    var testeval = 1;
    alert("k=" + k)
    eval('testeval='+ k++); 
    alert("k=" + k); 

If you attach this script to a basic HTML page, sometimes k will report 7 instead of 6 on the second alert. Unfortunately, this is intermittent, and it seems like using my (non-public) webapp a lot encourages it along.
 
I've also reproduced the problem without alerts so I don't think they are related. In my webapp where I can more consistently reproduce the problem, I found that if I put brackets around the '++i' part to make it '(++i)', the bug stops. Also, moving the string construction to a temporary variable also stops the bug. Finally, changing the eval(...) to alert(...) stopped the bug. So therefore, it seems quite likely that the bug occurs only when you have a pre or post increment as an argument to eval.



Reproducible: Sometimes

Steps to Reproduce:
See the example in details.
Actual Results:  
The second alert reports 7

Expected Results:  
Should've been 6
Summary: Javascript: post incrementing a variable as an argument to eval sometimes results in incrementing by 2 → Javascript: pre/post incrementing a variable as an argument to eval sometimes results in incrementing by 2
Reporter, please retest with Firefox 3.6.12 or later in a fresh profile (http://support.mozilla.com/kb/Managing+profiles). Also update your plugins (flash, adobe reader, java, quicktime, silverlight, etc.) Go to the developer's website and download the latest version from there. If you no longer see this issue, please close this bug as RESOLVED, WORKSFORME. If you do see the bug, please post a comment.
Whiteboard: [CLOSEME 2010-12-01]
No reply, INCOMPLETE. Please retest with Firefox 3.6.12 or later and a new profile (http://support.mozilla.com/kb/Managing+profiles). If you continue to see this issue with the newest firefox and a new profile, then please comment on this bug.
Status: UNCONFIRMED → RESOLVED
Closed: 14 years ago
Resolution: --- → INCOMPLETE
You need to log in before you can comment on or make changes to this bug.