All users were logged out of Bugzilla on October 13th, 2018

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

RESOLVED INVALID

Status

()

RESOLVED INVALID
8 years ago
8 years ago

People

(Reporter: internauta1024a, Unassigned)

Tracking

Firefox Tracking Flags

(Not tracked)

Details

(URL)

(Reporter)

Description

8 years ago
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.

Comment 1

8 years ago
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

Comment 2

8 years ago
Yeah, invalid.  You popped the elements, which requires deleting them, so they're not visited when iteration would hit them.
Status: UNCONFIRMED → RESOLVED
Last Resolved: 8 years ago
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.