[JS] Null Sensitive Context (new library) - #1175
Conversation
xiemaisi
left a comment
There was a problem hiding this comment.
Looks useful, but can be simplified considerably. Also, please add some tests.
|
@mc-semmle: this PR does not require a doc review. This bit seems to duplicate the crashing cases of this PR: Once this PR lands, perhaps we should try to use your changes to make https://github.com/Semmle/ql/blob/86040575b1533b28adf284ecd1af7a9220d015cc/javascript/ql/src/Expressions/UnneededDefensiveProgramming.ql flag more cases. |
|
Thanks @esben-semmle - no worries. |
|
On second thought, I'd suggest replacing all of these abstract classes with a simple predicate on |
Would this make it possible to include the for-of statement iteration domain? Or should we omit that in preference of a method predicate? |
You can include that in either style, but I think just implementing the whole thing as a member predicate of |
[EDIT] Ok, in talking w/ Aditya, the solution resolved itself into being a predicate that is either |
xiemaisi
left a comment
There was a problem hiding this comment.
Yes, this is the approach I had in mind. A few minor comments, but overall lgtm.
|
I'd suggest whitelisting the following cases as not "null sensitive":
These explicitly serve the purpose of converting a value to a number, so I wouldn't say it's indicative of "undesired behaviour" to get |
|
You could also consider adding some recursive cases:
|
xiemaisi
left a comment
There was a problem hiding this comment.
Getting close! Just a few minor things left to address.
Co-Authored-By: psygnisfive <psygnisfive@users.noreply.github.com>
Co-Authored-By: psygnisfive <psygnisfive@users.noreply.github.com>
This reverts commit 78407f8.
|
Tests are failing. |
This PR adds a new library to the JS libs to describe (local) evaluation contexts in which the values of expressions in that context cannot be
nullorundefined, and where using those values will cause an error to be thrown or cause other undesirable behavior.For example, in the expression
fac(5), the expressionfaccannot compute tonullorundefined(nor replaced with them), without the code producing an error (in this case, a runtimeTypeError).The library has one abstract class,
NullSensitiveContext, which has a large number of concrete classes for different contexts. By convention, the names of the context classes are<NameOfExprClass> + <NameOfPrincipalArgument>. So for example, in theCallExprfac(5), because thefacpart is thecallee(getCallee), the context that it inhabits within that expression as its principal argument isCallExprCallee.