Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Fix bug with arrays with widened numeric properties #1981

Closed
wants to merge 5 commits into from

Conversation

trueadm
Copy link
Contributor

@trueadm trueadm commented May 17, 2018

Release notes: none

This PR fixes a bug where prototype methods on unknown arrays with widened numeric properties were incorrectly being used instead of following the route to filter which methods were safe or not. The functionality and logic for this was pulled out, into its own function so it can be re-used in places and tidied up.

@@ -561,6 +573,9 @@ export default class AbstractObjectValue extends AbstractValue {
}
invariant(d1val instanceof Value);
invariant(d2val instanceof Value);
if (d1val === d2val) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looked like an obvious optimization here, unless I'm mistaken?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but joinValuesAsConditional should also do this optimization, so while this is faster, it is also a teeny bit of code bloat.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually found a case just now where joinValuesAsConditional's simplify step hits the limit and returns the abstract condition, even though d1val === d2val.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like something we should try to fix in joinValuesAsConditional. Any chance you can come up with a repro?

if (typeof P === "string") {
// these are safe methods to allow, as they return a new array
// so we use the ordinary get for these cases. Reduce can be
// unsafe, but we check for that in the prototype method
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reduce is not guaranteed to return an array, and we removed that logic. Let's fix up the comment too.

Copy link

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@trueadm is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

Copy link

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@trueadm is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@trueadm
Copy link
Contributor Author

trueadm commented May 17, 2018

The depcheck test was passing in this PR and in recent commits is failing. I'm not sure why, it started failing after I edited the comment.

@hermanventer
Copy link
Contributor

hermanventer commented May 17, 2018

The depcheck test is flaky on Circle. Nikolai reported it the Flow team, but so far no enthusiasm from their part. To be fair, this a hard thing to debug.

Copy link

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@trueadm is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

if (typeof P === "string") {
// these are safe methods to allow, as they return a new array
// so we use the ordinary get for these cases.
if (P === "map" || P === "slice" || P === "filter" || P === "concat") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought we got rid of this whitelist?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, we need them. We need to access the array prototype methods, but only the ones that create new arrays.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants