Closed Bug 576124 Opened 12 years ago Closed 12 years ago

locally declared regexp keeps memory of position

Categories

(Core :: JavaScript Engine, defect)

x86
Windows 7
defect
Not set
normal

Tracking

()

RESOLVED DUPLICATE of bug 98409

People

(Reporter: angelo.borsotti, Unassigned)

Details

User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.6) Gecko/20100625 Firefox/3.6.6
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.6) Gecko/20100625 Firefox/3.6.6

A regexp that is declared as a local variable of a function
keeps memory of the lastIndex property between successive
executions of the function.

Reproducible: Always

Steps to Reproduce:
1.open the page:
<html>
<head>
<script type="text/javascript">
function f(s){
    var reg = /[abc]/g;
    document.write(reg.lastIndex + " ");
    var test = reg.test(s);
    document.write(test + " ");
}
f("a");
f("b");
</script>
</head>
</html>

2. note what the browser shows
Actual Results:  
0 true 1 false 

Expected Results:  
0 true 0 true 

The regexp is declared inside a function; thus it should be
created afresh and properly initialized each time the
function is called. Instead, it seems that it is reused
from one execution to the next without having properly
been initialized each time.
I get the expected results on trunk.  This was an ES spec change, as I recall; the behavior we used to have was what the spec used to say.
Assignee: nobody → general
Component: General → JavaScript Engine
QA Contact: general → general
Whiteboard: DUPEME
Status: UNCONFIRMED → RESOLVED
Closed: 12 years ago
Resolution: --- → DUPLICATE
Duplicate of bug: regexpliteralflaw
Whiteboard: DUPEME
You need to log in before you can comment on or make changes to this bug.