Correct Object.keys to collect only enumerable property names (#3952)

In case of Proxy objects, there were no property descriptor checks when
collecting enumerable properties. Therefore, all the non-enumerable
Proxy.target properties were listed as well.

JerryScript-DCO-1.0-Signed-off-by: Roland Takacs rtakacs@inf.u-szeged.hu
This commit is contained in:
Roland Takacs
2020-06-30 13:13:18 +02:00
committed by GitHub
parent 89342ea503
commit 034b3b63f5
2 changed files with 49 additions and 2 deletions
+19 -1
View File
@@ -78,7 +78,7 @@ var proxy = new Proxy(target, handler);
array_check(Reflect.ownKeys(proxy), ["foo", "bar", symA]);
array_check(Object.getOwnPropertyNames(proxy), ["foo", "bar"]);
array_check(Object.keys(proxy), ["foo", "bar"]);
array_check(Object.keys(proxy), []);
array_check(Object.getOwnPropertySymbols(proxy), [symA]);
handler.ownKeys = function(target) {return Object.getOwnPropertyNames(target);};
@@ -223,3 +223,21 @@ try {
} catch (e) {
assert(e instanceof TypeError);
}
var object = {};
Object.defineProperties(object, {
a: { value: 42, enumerable: false },
b: { value: "foo", enumerable: true },
c: { value: "bar", enumerable: false }
});
var handler = {
ownKeys(target) {
return Reflect.ownKeys(target);
}
};
var proxy = new Proxy(object, handler);
assert(Object.keys(proxy).length === 1);
assert(Object.keys(proxy)[0] === "b");