Coverage of for-in

Gareth Smith gds at doc.ic.ac.uk
Tue Apr 16 10:18:18 PDT 2013


There doesn't seem to be any coverage of the issue described in the
following V8 and WebKit bugs:

http://code.google.com/p/v8/issues/detail?id=705
https://bugs.webkit.org/show_bug.cgi?id=38970

The issue is that if a non-enumerable property shadows an enumerable
property, for-in should not enumerate it.

I've suggested a possible test here:

https://bugs.ecmascript.org/show_bug.cgi?id=1445

While I was looking for tests which cover the issue above, I noticed
test ch12/12.6/12.6.4/12.6.4-2.js (quoted below).

It sets up a non-enumerable property in the prototype of an object we
wish to loop over. It does not shadow this property. It does not test to
see if that property is enumerated. Is this test intended to test a
behaviour I haven't thought of, or is there a bug in this test?

Thanks,

Gareth.

function testcase() {
        var obj = {};

        var proto = {};

        Object.defineProperty(proto, "prop", {
            value: "inheritedValue",
            enumerable: false,
            configurable: true,
            writable: true
        });

        var ConstructFun = function () { };
        ConstructFun.prototype = proto;

        var child = new ConstructFun();

        Object.defineProperty(child, "prop1", {
            value: "overridedValue1",
            enumerable: false
        });
        Object.defineProperty(child, "prop2", {
            value: "overridedValue2",
            enumerable: true
        });
        var accessedProp1 = false;
        var accessedProp2 = false;

        for (var p in child) {
            if (child.hasOwnProperty(p)) {
                if (p === "prop1") {
                    accessedProp1 = true;
                }
                if (p === "prop2") {
                    accessedProp2 = true;
                }
            }
        }
        return !accessedProp1 && accessedProp2 && child.prop1 === "overridedValue1" && child.prop2 === "overridedValue2";
    }
runTestCase(testcase);


More information about the test262-discuss mailing list