mirror of
https://github.com/facebookarchive/prepack.git
synced 2024-09-11 14:46:37 +03:00
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:
parent
8b6307a121
commit
2c79cb103d
@ -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") {
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
12
test/serializer/optimized-functions/ArrayFrom5.js
Normal file
12
test/serializer/optimized-functions/ArrayFrom5.js
Normal 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)
|
||||
};
|
Loading…
Reference in New Issue
Block a user