prepack
prepack copied to clipboard
$Get unknown property doesn't consider what might be on the prototype chain
(function () {
var key = __abstract('string', '("y")');
function Foo() {
}
Foo.prototype.x = function() {
};
var obj = new Foo();
obj[key] = 123;
result = typeof obj.x === 'function' ? obj.x() : null;
})();
This assumes that if we are trying to read a property, it must be one of the unknown ones. However, it could be one of the ones on the prototype.
https://github.com/facebook/prepack/blob/master/src/values/ObjectValue.js#L570
This seems difficult to solve in general but if we know the prototype at the time of the call, we could possibly add its keys to the condition.
The more specific case where I think this will come up a lot is for arrays.
var value = arrayWithUnknownProperties[5];
arrayWithUnknownProperties.map(...);
That particular use case could potentially be helped by special casing unknown numeric properties from arbitrary properties. That way we would know that if all unknown properties are numeric, any non-numeric property would access the prototype.