Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7d183ea

Browse files
committed
moves functionality over to Expr method per PR change requests
1 parent e4c5fd4 commit 7d183ea

2 files changed

Lines changed: 23 additions & 488 deletions

File tree

javascript/ql/src/semmle/javascript/Expr.qll

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,29 @@ class Expr extends @expr, ExprOrStmt, ExprOrType, AST::ValueNode {
161161
* file that was extracted without type information.
162162
*/
163163
Type getType() { ast_node_type(this, result) }
164+
165+
/**
166+
* Holds if the syntactic context that the expression appears in relies on the expression
167+
* being non-null/non-undefined.
168+
*/
169+
predicate getNullSensitiveContext() {
170+
exists(ExprOrStmt ctx |
171+
this = ctx.(PropAccess).getBase() or
172+
this = ctx.(IndexExpr).getPropertyNameExpr() or
173+
this = ctx.(InvokeExpr).getCallee() or
174+
(this = ctx.(BinaryExpr).getAnOperand() and
175+
not ctx instanceof LogicalBinaryExpr and
176+
not ctx instanceof EqualityTest) or
177+
(this = ctx.(UnaryExpr).getOperand() and
178+
not ctx instanceof LogNotExpr) or
179+
this = ctx.(UpdateExpr).getOperand() or
180+
this = ctx.(CompoundAssignExpr).getLhs() or
181+
this = ctx.(CompoundAssignExpr).getRhs() or
182+
this = ctx.(AssignExpr).getRhs() or
183+
this = ctx.(SpreadElement).getOperand() or
184+
this = ctx.(ForOfStmt).getIterationDomain()
185+
)
186+
}
164187
}
165188

166189
/** An identifier. */

0 commit comments

Comments
 (0)