Bug 104506

Summary: The order of objects in an array are not sequential - Moz, FF, IE, Opera are okay
Product: [Applications] konqueror Reporter: Charles Phoenix <phoenixreads>
Component: kjsAssignee: Konqueror Developers <konq-bugs>
Status: RESOLVED DUPLICATE    
Severity: normal    
Priority: NOR    
Version: unspecified   
Target Milestone: ---   
Platform: unspecified   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:

Description Charles Phoenix 2005-04-25 04:58:42 UTC
Version:           3.4.0 (using KDE 3.4.0, Gentoo)
Compiler:          gcc version 3.3.5-20050130 (Gentoo Linux 3.3.5.20050130-r1, ssp-3.3.5.20050130-1, pie-8.7.7.1)
OS:                Linux (i686) release 2.6.11-gentoo-r6

This is part of a large program... experimentation with rollovers and slideshows.

The functions in question...

JS_FADE.addImage = function(imgName, img, caption) {
	JS_FADE.gallery[imgName] = new Image();
	JS_FADE.gallery[imgName].src = img;
	JS_FADE.gallery[imgName].caption = caption;
	JS_FADE.gallery[imgName].imgName = imgName;
	JS_FADE.cycleListUpdate = false;
}

JS_FADE.updateCycleList = function() {
	var i;
	var j = 0;
	for (i in JS_FADE.gallery) {
		JS_FADE.cycleList[j] = JS_FADE.gallery[i].imgName;
		j++;
	}
	JS_FADE.cycleListUpdate = true;
}

and then JS_FADE.gallery is referenced
	newImgName = JS_FADE.cycleList[JS_FADE.cycleIndex];
	JS_FADE.fadeInImage(JS_FADE.gallery[newImgName].imgName);

I presume I am making a few mistakes in style, but it works in the other browser and sequential order is maintained.



The first function is called externally like so...

	JS_FADE.addImage ('apple', "images/apple.jpg", "This is an apple.");
	JS_FADE.addImage ('banana', "images/banana.jpg", "This is a banana.");
	JS_FADE.addImage ('cherries', "images/cherries.jpg", "These are cherries.");
	JS_FADE.addImage ('orange', "images/orange.jpg", "This is an orange.");
	JS_FADE.addImage ('pear', "images/pear.jpg", "This is a pear.");
	JS_FADE.addImage ('pineapple', "images/pineapple.jpg", "This is a pineapple.");
	JS_FADE.addImage ('prune', "images/prune.jpg", "This is a prune.");
	JS_FADE.addImage ('strawberry', "images/strawberry.jpg", "This is a strawberry.");

thus establishing the sequential order, presumably the behavior is the equivalent of a push on stack command?

but... to the order ends up being
pear, apple, pineapple, prune, orange, cherries, strawberry, banana


I compile from source so some gremlin could have awaken, unknown.

If someone wants to chase this I can send them a copy of my work ~300Kbytes.

Sidenote, is opacity working?
If not I will file another report.
Comment 1 Thiago Macieira 2005-04-25 06:11:15 UTC
So, if you do:

arr['cherry'] = 1;
arr['apple'] = 1;
arr['banana'] = 1;
for (i in arr)
  document.write(i + ' ');

The output will not necessarily be "cherry apple banana"?

If that is the case, unless the ECMA standard makes this contract, I don't see why the order should be kept. Alphabetic might be expected, but, again, unless mandated by the standard, there is no reason to. The internal representation is probably a hashing-table, whose iteration order is not guaranteed.

In fact, we can relate to:

arr[2] = 1;
arr[0] = 1;
arr[1] = 1;
for (i in arr)
  document.write(i);
The output will probably not be "201".
Comment 2 Maksim Orlovich 2005-04-25 06:15:00 UTC
See bug #28474, I think this is a dupe
Comment 3 Charles Phoenix 2005-04-25 13:03:48 UTC
Granted it is not "official" behavior but it is "unofficial" behavior. It comes down to a design choice.

Something to add to the learning... do not program based on *any* assumptions.

Thank you.

And yes you can mark this as dupe.
Comment 4 Thiago Macieira 2005-04-26 04:39:17 UTC
Reopening to mark as duplicate.
Comment 5 Thiago Macieira 2005-04-26 04:39:34 UTC

*** This bug has been marked as a duplicate of 28474 ***