[wpkg-users] [Bug 209] Replace variables in package revisions by their value in local wpkg.xml file

Malte Starostik malte at malte.homeip.net
Sat Jul 9 18:17:39 CEST 2011


Am Samstag, 9. Juli 2011, 17:24:11 schrieb bugzilla-daemon at bugzilla.wpkg.org:
> Just fixed another issue with LCID matching which caused some variable
> scope clash in WSH (maybe WSH bug). If WSH for loops are nested and
> internal for loop uses same local variable it overwrites the outer for
> loop variable:
> 
> for (var i=0; i<x; i++) {
>   for (var i=0; i<y; i++) {
>   }
> }
> The inner for loop will change "i" of the outer one.
> 
> Worked around by simply renaming variables.

Not a WSH bug.  In JS, var always has function (or eval) scope.  The variable 
is even defined before its declared, only the value is not yet assigned:

function foo() {
  // at this point, an object named "x" already exists in foo()'s execution 
context and has an undefined value
  var x = 42; // now 42 is assigned to that very object
  var x = 23; // new value, but still the same object named "x"
  for (var x = 0; x < 12; ++x) {
    // x iterates from 0 to 12, overwriting the object introduced at the 
beginning of foo()
      for (var x = 0; x < 12; ++x) {
          // same
      }
  }
}

Loops don't introduce their own scope as they do in C++.

FWIW, see sec. 10.3, 10.5, and 12.2 of http://www.ecma-
international.org/publications/files/ECMA-ST/Ecma-262.pdf

Cheers,
Malte



More information about the wpkg-users mailing list