Ensure we handle numeric properties on $GetPartial path (#2205)

Summary:
Release notes: none

We were missing logic for handling abstract arrays with unknown numeric properties when we attempt to get a partial value on the array. I've added a regression test too.
Closes https://github.com/facebook/prepack/pull/2205

Differential Revision: D8732181

Pulled By: trueadm

fbshipit-source-id: 6002eac4b7d4d0b842407a3bb9ea9bcec19f486b
This commit is contained in:
Dominic Gannaway 2018-07-04 07:24:41 -07:00 committed by Facebook Github Bot
parent 8b6307a121
commit 2c79cb103d
3 changed files with 17 additions and 2 deletions

View File

@ -25,7 +25,6 @@ import {
ObjectValue,
ProxyValue,
StringValue,
SymbolValue,
UndefinedValue,
Value,
} from "../values/index.js";
@ -555,7 +554,7 @@ export function GetTemplateObject(realm: Realm, templateLiteral: BabelNodeTempla
return template;
}
export function GetFromArrayWithWidenedNumericProperty(realm: Realm, arr: ArrayValue, P: string | SymbolValue): Value {
export function GetFromArrayWithWidenedNumericProperty(realm: Realm, arr: ArrayValue, P: string | Value): Value {
let proto = arr.$GetPrototypeOf();
invariant(proto instanceof ObjectValue && proto === realm.intrinsics.ArrayPrototype);
if (typeof P === "string") {

View File

@ -819,6 +819,10 @@ export default class ObjectValue extends ConcreteValue {
if (desc !== undefined) {
let val = desc.value;
invariant(val instanceof AbstractValue);
if (val.kind === "widened numeric property") {
invariant(Receiver instanceof ArrayValue && ArrayValue.isIntrinsicAndHasWidenedNumericProperty(Receiver));
return GetFromArrayWithWidenedNumericProperty(this.$Realm, Receiver, P instanceof StringValue ? P.value : P);
}
result = this.specializeJoin(val, P);
}
}

View File

@ -0,0 +1,12 @@
function fn(x, y) {
var foo = Array.from(x);
return foo[y] + 5;
}
if (global.__optimize) __optimize(fn);
inspect = function() {
return JSON.stringify([10], 0)
};