Subj : "for each" bug To : netscape.public.mozilla.jseng From : Jason Date : Tue Apr 26 2005 08:13 am I'm using Shanti Rao's jsdb & have run across a bug, it seems to be in the Spidermonkey portion of it, so he encouraged me to post it here. The bug is in the "for each" keyword... which is odd because I can't find any documentation of there actually being a "for each" keyword in Javascript (but *you* try doing a web search on "for each" and see where it gets you!!!), though there seems to be something in the Spidermonkey source tree (JSOP_FOREACH in http://lxr.mozilla.org/mozilla/source/js/src/jsparse.c). (by the way, could someone with clout ****please**** urge mozilla.org to add a feature to the LXR source browser which limits scope of searches to a particular source directory? Otherwise there is no way to search only the Spidermonkey source unless you download it yourself) The "for each" keyword seems to be disabled in the standard xpcshell.exe build so I can't reproduce it in that. Here's the bug: Side effects seem to happen in a variable unrelated to the for each loop (note that the outer for() loop morphs into a "for each()" loop on its second and subsequent iterations) function foreachbug(do_bug) { var i,j,k; var d_a; var Tlookupi = []; Tlookupi[7] = "element seven"; Tlookupi[6] = "element six"; Tlookupi[8] = "element eight"; d_a = ["bing","bong","boom"]; for (j in Tlookupi) { print("\n"+j+"\n"); for (i = 1; i <= 3; i++) { if (do_bug) { for each (k in d_a) print(k+":::"); } else { for (k in d_a) print(k+":::"); } } print("\n"+j+"\n"); } } js>foreachbug(false) 7 0:::1:::2:::0:::1:::2:::0:::1:::2::: 7 6 0:::1:::2:::0:::1:::2:::0:::1:::2::: 6 8 0:::1:::2:::0:::1:::2:::0:::1:::2::: 8 js>foreachbug(true) 7 bing:::bong:::boom:::bing:::bong:::boom:::bing:::bong:::boom::: 7 element six bing:::bong:::boom:::bing:::bong:::boom:::bing:::bong:::boom::: element six element eight bing:::bong:::boom:::bing:::bong:::boom:::bing:::bong:::boom::: element eight .