Improve isEnumerable check with a for-in loop for string names (#880)

Ref https://github.com/tc39/test262/pull/879#discussion_r104128520
This commit is contained in:
Leo Balter 2017-03-13 13:48:33 -04:00 committed by Tom Care
parent 6c20a250f2
commit 866d7f8d8e
1 changed files with 16 additions and 1 deletions

View File

@ -11,7 +11,22 @@ function isConfigurable(obj, name) {
}
function isEnumerable(obj, name) {
return Object.prototype.hasOwnProperty.call(obj, name) &&
var stringCheck;
if (typeof name === "string") {
for (var x in obj) {
if (x === name) {
stringCheck = true;
break;
}
}
} else {
// skip it if name is not string, works for Symbol names.
stringCheck = true;
}
return stringCheck &&
Object.prototype.hasOwnProperty.call(obj, name) &&
Object.prototype.propertyIsEnumerable.call(obj, name);
}