for-in and for-each-in fail for the "arguments" object.

RESOLVED DUPLICATE of bug 352203

Status

()

Firefox
General
--
minor
RESOLVED DUPLICATE of bug 352203
9 years ago
9 years ago

People

(Reporter: Chris Carter, Unassigned)

Tracking

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

9 years ago
User-Agent:       Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.1) Gecko/2008070206 Firefox/3.0.1 FirePHP/0.1.2
Build Identifier: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.1) Gecko/2008070206 Firefox/3.0.1 FirePHP/0.1.2

A function's local "arguments" object cannot be enumerated via the convenience loops.  This requires developers to provide an extra implementation when either an object or the function's arguments will be looped through depending on the situation.  (My use-case is available if necessary.)

Reproducible: Always

Steps to Reproduce:
Within a function, use a for-in or for-each-in loop to enumerate the function's arguments.  HTML-enclosed test case:
<html>
	<body>
		<script type="text/javascript">
			function foo(){
				for each(var argument in arguments){
					document.write(argument + '<br>');
				}
				for(var index in arguments){
					document.write(index + '<br>');
				}
				for(var i = 0; i < arguments.length; i++){
					document.write(arguments[i] + '<br>');
				}
				document.write((0 in arguments) + '<br>');
				document.write(arguments[0]);
			}
			foo('bar');
		</script>
	</body>
</html>
Actual Results:  
bar
true
bar

Expected Results:  
bar
0
bar
true
bar

The workaround is to use an ordinary for loop as demonstrated above.
(Reporter)

Comment 1

9 years ago
After realizing my mistake of testing in 3.0.1, I have verified that this bug also occurs in Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.1) Gecko/2008072820 Firefox/3.0.1

Updated

9 years ago
Status: UNCONFIRMED → RESOLVED
Last Resolved: 9 years ago
Resolution: --- → DUPLICATE
Duplicate of bug: 352203
You need to log in before you can comment on or make changes to this bug.