archives

« Bugzilla Issues Index

#1445 — Coverage: 12.6.4 Non-enumerable property shadows enumerable one.


There seem to be no tests which cover the bug reported here in V8 and WebKit:

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.

Would the following do?

function testcase() {
var proto = {prop:"inheritedValue"};

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

var child = new ConstructFun();
Object.defineProperty(child, "prop", {
value: "overriddenValue",
enumerable: false,
configurable: true,
writable: true
});

var numVisibleProperties = 0;
for (var k in child) {
numVisibleProperties++;
}

return numVisibleProperties === 0;
}

runTestCase(testcase);


As discussed on-list[1], here is a better version of this test:

function testcase() {
var proto = {prop:"inheritedValue"};

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

var child = new ConstructFun();
Object.defineProperty(child, "prop", {
value: "overriddenValue",
enumerable: false,
configurable: true,
writable: true
});

for (var k in child) {
if(k==="prop") {
return false; // prop is shadowed by a non-enumerable property.
}
}
return true; // We didn't see the non-enumerable 'prop'.
}




[1] https://mail.mozilla.org/pipermail/test262-discuss/2013-April/000180.html