2.1.40 [ECMA-262-1999] Section 12.6.4, The for-in Statement

V0059:

The production IterationStatement : for ( LeftHandSideExpression in Expression ) Statement is evaluated as follows:

  1. Evaluate the Expression.

  2. Call GetValue(Result(1)).

    1. __If Type(Result(2) is VarDate, return (normal, empty, empty).__

    2. __If Result(2) is either null or undefined, return (normal, empty, empty).__

  3. Call ToObject(Result(2)).

  4. Let V = empty.

  5. Get the name of the next property of Result(3) that doesn't have the DontEnum attribute. If there is no such property, go to step 14.

  6. Evaluate the LeftHandSideExpression ( it may be evaluated repeatedly).

  7. Call PutValue(Result(6), Result(5)).

  8. Evaluate Statement.

  9. If Result(8).value is not empty, let V = Result(8).value.

  10. If Result(8).type is break and Result(8).target is in the current label set, go to step 14.

  11. If Result(8).type is continue and Result(8).target is in the current label set, go to step 5.

  12. If Result(8) is an abrupt completion, return Result(8).

  13. Go to step 5.

  14. Return (normal, V, empty).

V0060:

The production IterationStatement : for ( var VariableDeclarationNoIn in Expression ) Statement is evaluated as follows:

  1. Evaluate VariableDeclarationNoIn.

  2. Evaluate Expression.

    1. __If Type(Result(2)) is VarDate, return (normal, empty, empty).__

    2. __If Result(2) is either null or undefined, return (normal, empty, empty).__

  3. Call GetValue(Result(2)).

  4. Call ToObject(Result(3)).

  5. Let V = empty.

  6. Get the name of the next property of Result(4) that doesn't have the DontEnum attribute. If there is no such property, go to step 15.

  7. Evaluate Result(1) as if it were an Identifier; see [ECMA-262-1999] 11.1.2. (yes, it may be evaluated repeatedly).

  8. Call PutValue(Result(7), Result(6)).

  9. Evaluate Statement.

  10. If Result(9).value is not empty, let V = Result(9).value.

  11. If Result(9).type is break and Result(9).target is in the current label set, go to step 15.

  12. If Result(9).type is continue and Result(9).target is in the current label set, go to step 6.

  13. If Result(8) is an abrupt completion, return Result(8).

  14. Go to step 6.

  15. Return (normal, V, empty).

In JScript 5.x no interations of the Statement are performed and no exception is thrown if the value of Expression is either null or undefined.

V0061:

The mechanics of enumerating the properties (step 5 in the first algorithm, step 6 in the second) is implementation dependent. The order of enumeration is defined by the object. Properties of the object being enumerated may be deleted during enumeration. If a property that has not yet been visited during enumeration is deleted, then it will not be visited. If new properties are added to the object being enumerated during enumeration, the newly added properties are not guaranteed to be visited in the active enumeration.

Enumerating the properties of an object includes enumerating properties of its prototype, and the prototype of the prototype, and so on, recursively; but a property of a prototype is not enumerated if it is "shadowed" because some previous object in the prototype chain has a property with the same name.

Note that JScript 5.x under Internet Explorer 7 or 8 defines properties such that their DontEnum attribute is inherited from prototype properties with the same name. As a result of this, any properties that have the same name as built-in properties of a prototype object that have the DontEnum attribute are not included in an enumeration. However JScript 5.x under Internet Explorer 9 includes the properties that have the same name as built-in properties of a prototype object in an enumeration.

In JScript 5.x the order of property enumeration is highly dependent upon dynamic characteristics of a program including the order in which properties are created and the order in which individual properties are accessed. These dynamic effects are most pronounced when enumerable properties are inherited from prototypes. For this reason, is not possible to provide a generalized specification of properties enumeration order that applies to all objects. However, in JScript 5.x, if an object inherits no enumerable properties from its prototypes, the object's properties will be enumerated in the order in which they were created. The order of property enumeration in JScript 5.x under Internet Explorer 9 may be different from the order returned by JScript 5.x under Internet Explorer 7 or 8.