Closed Bug 579859 Opened 14 years ago Closed 14 years ago

Method array.pop() and other removing elements array method not working in array.filter callback function.

Categories

(Core :: JavaScript Engine, defect)

x86
All
defect
Not set
normal

Tracking

()

RESOLVED INVALID

People

(Reporter: internauta1024a, Unassigned)

References

()

Details

User-Agent:       Mozilla/5.0 (X11; U; Linux i686; pl; rv:1.9.2.6) Gecko/20100625 OlaOS/Dom-8.04 Firefox/3.6.6
Build Identifier: Mozilla/5.0 (X11; U; Linux i686; pl; rv:1.9.2.6) Gecko/20100625 OlaOS/Dom-8.04 Firefox/3.6.6

Method array.pop() and other removing elements array method not working correct in array.filter callback function.(Stopping in 1/2 all iteration).

<html>
	<head>
		<script>
			var numb,numb2,index1,index2
			function ftr2(element, index, array) {
			numb2.push(array[index])
			index2= index+1
//			alert("Iteration for array.push() method : " + index2)
			}
			function ftr1(element, index, array) {
				numb.pop()
				index1= index+1
//			alert("Iteration for array.pop() method : " + index1)
			}
			 function test1(){
				numb2 = ["1", "2", "3", "4"]
				numb2.filter(ftr2)
				numb = ["1", "2", "3", "4"]
				numb.filter(ftr1)
				alert("Iteration for array.push() method : " + index2 +"\n"+"Iteration for array.pop() method : " + index1 )
			}
		</script>
	</head>
	<body onload="test1()">
	</body>
</html>

Reproducible: Always

Steps to Reproduce:
1.Try example code.
2.Array numb2.length = array mumb.length
Iterations for method array.push() =4
Iterations for method array.pop() =2
3.Iterations for method array.pop() =2 (not work correctly)

3.
The behaviour seems to be as expected

"The range of elements processed by filter is set before the first invocation of callback. Elements which are appended to the array after the call to filter begins will not be visited by callback. If existing elements of the array are changed, or deleted, their value as passed to callback will be the value at the time filter visits them; elements that are deleted are not visited."

https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/filter#Description

=> Invalid ?
Assignee: nobody → general
Component: General → JavaScript Engine
Product: Firefox → Core
QA Contact: general → general
Yeah, invalid.  You popped the elements, which requires deleting them, so they're not visited when iteration would hit them.
Status: UNCONFIRMED → RESOLVED
Closed: 14 years ago
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.