-
Notifications
You must be signed in to change notification settings - Fork 1.9k
JS: introduce DataFlow::ClassNode #764
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
ghost
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Two minor documentation concerns.
This requires a change note and a thorough evaluation.
If the taint tracking experiments with this change are inconclusive, you could try porting js/mixed-static-instance-this-access to get an additional data point.
| * A data flow node corresponding to a class definition or a function definition | ||
| * acting as a class. | ||
| * | ||
| * The following patterns are recognized as classes and methods: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want a note here about how to extend the set of recognized patterns?
| /** | ||
| * Gets an instance method with the given name, if any. | ||
| */ | ||
| abstract FunctionNode getAnInstanceMethod(string name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should mention that the prototype chains are not traversed for these lookups.
I am not sure if the prototype traversal should be implicit or explicit one day.
|
To clarify, this PR just contains the And this is exactly why I included it in #760.
I don't see why I should first put this in its own PR and then bundle it something else? If we wanted it bundled with the use-case, we had #760. |
xiemaisi
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, with minor suggestion for simplification.
| result = method.getBody().flow() | ||
| ) | ||
| or | ||
| result = getAPropertyWrite(name).getRhs().getALocalSource() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| result = getAPropertyWrite(name).getRhs().getALocalSource() | |
| result = getAPropertySource(name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto below.
To clarify: The performance of #760 was characterized as:
I suspect the performance hiccups are mainly caused by to the two other commits of #760 then. The suggested port of |
|
I tried integrating it with One particular problem is that we can't tell if a static member is intended to be used as a "named constructor", like here. |
|
Hmm. Thanks for trying. But at least it is now clear that the implementation scales. |
|
I've pushed a commit that adds |
ghost
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes LGTM, but there is one test failure.
| * | ||
| * Does not include methods from superclasses. | ||
| */ | ||
| FunctionNode getAnInstanceMethod(string name) { result = impl.getAnInstanceMethod(name) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here and below, I wonder whether it is really worth including "a"/"an" in the predicate name and doc comment. Of course, it is technically correct since we don't assume/enforce uniqueness, but in the majority of cases we probably would expect the result to be unique, so having an overly general name might lead to confusion and bad auto-complete experience.
What do you think?
(We should, of course, still mention the possibility of multiple results in the doc comment.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I considered this as well, for the same reasons, but I think "a"/"an" should be used here.
Some arguments for:
- the rest of the
SourceNodegetters use that convention - multiple prototypes are possible
- the method definitions may be conditional
- unlike ES6 classes, these class nodes are not always syntactic, the "a"/"an" prefix kind of reflects that
- if we later add support for lookups in the prototype hierarchy, I think we want the "a/an" prefix, so it would be nice if we had some consistency between similar lookups
(this list is probably a rehash of what you already know)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm also against the a/an prefix. Even if it's technically possible, it's confusing and extremely rare in practice, and inconsistent with other APIs for things that are unique in practice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. Let us remove it then.
e66fe7e to
4b4daa6
Compare
|
I've reverted the a/an prefix from I've also excluded getters/setters from these predicates as that was the main situation where they had multiple returns, but it was in general unfortunate that you couldn't tell them apart using this API. I have instead introduced Feel free to suggest another terminology, keeping in mind that @esben-semmle @xiemaisi could you take another look at the latest commit? |
|
This looks good to go, but have you sanity checked the performance of the latest commit? |
|
Never mind. I keep forgetting that this is unevaluable.. |
Spin-off from #760