Skip to content

Commit 8e9d8c1

Browse files
committed
JS: Improve comments in FunctionBodyFeatures.qll
1 parent 2aea325 commit 8e9d8c1

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

javascript/ql/experimental/adaptivethreatmodeling/lib/experimental/adaptivethreatmodeling/FunctionBodyFeatures.qll

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ import javascript
88
private import FeaturizationConfig
99

1010
/**
11-
* Returns a tokenized representation of the AST node for use in the `enclosingFunctionBody`
12-
* feature.
11+
* Gets a tokenized representation of the AST node for use in the `enclosingFunctionBody` feature.
1312
*/
1413
string getTokenizedAstNode(ASTNode node) {
1514
// e.g. `x` -> "x"
@@ -34,7 +33,7 @@ string getTokenizedAstNode(ASTNode node) {
3433
result = node.(TemplateElement).getRawValue()
3534
}
3635

37-
/** Returns an AST node within the function `f` that we should featurize. */
36+
/** Gets an AST node within the function `f` that we should featurize. */
3837
pragma[inline]
3938
ASTNode getAnASTNodeToFeaturize(Function f) {
4039
result.getParent*() = f and
@@ -43,10 +42,14 @@ ASTNode getAnASTNodeToFeaturize(Function f) {
4342
}
4443

4544
/**
46-
* Get a function containing the endpoint that is suitable for featurization. In general, this
47-
* can associate an endpoint to multiple functions, since functions can be nested in JavaScript.
45+
* Gets a function that contains the endpoint.
46+
*
47+
* This can have multiple results, since functions can be nested in JavaScript. The predicate
48+
* `getRepresentativeFunctionForEndpoint` selects a single result from this predicate to use to
49+
* construct the `enclosingFunctionBody` feature for that endpoint. Generally you will want to use
50+
* `getRepresentativeFunctionForEndpoint` instead of this predicate.
4851
*/
49-
Function getAFunctionForEndpoint(DataFlow::Node endpoint) {
52+
private Function getAFunctionForEndpoint(DataFlow::Node endpoint) {
5053
// Performance optimization: Restrict the set of endpoints to the endpoints to featurize.
5154
endpoint = any(FeaturizationConfig cfg).getAnEndpointToFeaturize() and
5255
result = endpoint.getContainer().getEnclosingContainer*()
@@ -124,11 +127,14 @@ ASTNode getAnASTNodeWithAFeature(Function f) {
124127
result = getAnASTNodeToFeaturize(f)
125128
}
126129

127-
/** Holds if `location` is the location of an AST node within the function `function` and `token` is a node attribute associated with that AST node. */
130+
/**
131+
* Returns a featurized representation of the function that can be used to populate the
132+
* `enclosingFunctionBody` feature for an endpoint.
133+
*/
128134
string getBodyTokensFeature(Function function) {
129-
// Performance optimization: If a function has more than 256 body subtokens, then featurize it as absent. This
130-
// approximates the behavior of the classifer on non-generic body features where large body
131-
// features are replaced by the absent token.
135+
// Performance optimization: If a function has more than 256 body subtokens, then featurize it as
136+
// absent. This approximates the behavior of the classifer on non-generic body features where
137+
// large body features are replaced by the absent token.
132138
//
133139
// We count nodes instead of tokens because tokens are often not unique.
134140
strictcount(ASTNode node |

0 commit comments

Comments
 (0)