Subj : trouble with combination of "for/in" and "with" block To : netscape.public.mozilla.jseng From : archer Date : Fri Jul 23 2004 07:32 pm To moderator: this is a copy/follow-up to an earlier message which went out on error. Please kill first one if possible. Hi, I use JSRef 1.5r6a and encounter the following problem: an object from outer scope ("i" in the example below) is being modified by a "for...in" iteration when it is placed inside a "with" block. Older JSRef (1.4?) used to run the same code without the problem, and so does WScript/CScript. Also, there is NO problem if ANY one of conditions listed below is true: A. if "with" block is absent B. if "for( ; ; )" is used instead of "for...in" C. if object with same name as object in question appears somewhere else in the inner scope (of function "f()") I believe it is a bug, right? I did not find a test case in ftp://ftp.mozilla.org/pub/mozilla.org/js/js-tests-20021118.tar.gz that covers my set of conditions. I understand my case is very specific, and I totally agree that "with" statement is a poor practice to begin with. But this case that I have is present in an old code that I have running at a customer site. :( Is it possible to use some settings/switches to re-compile the JSRef to remedy this? Or does it have to be a fix? Please help if possible. var unrelated_object = {}; var i = 4444; function f() { with ( unrelated_object ) //// A. comment out to eliminate problem for ( var i in [7,7,7] ) {} // for ( var i = 333; 0; ) {} //// B. this flavor of "for" has no problem //var i = "lalala"; //// C. un-comment it to eliminate problem } f(); print( ''+ i ); // prints "2", whereas expected "4444" Thanks! Aleksey Chernoraenko, MetaCommunications Engineering. .