Skip to content

Commit c3c5b62

Browse files
committed
JS: Expose content-based accessors
1 parent b561826 commit c3c5b62

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

javascript/ql/lib/semmle/javascript/ApiGraphs.qll

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -230,22 +230,33 @@ module API {
230230
}
231231

232232
/**
233-
* Gets a node representing an arbitrary array element in the array represented by this node.
233+
* Gets a representative for the `content` of this value.
234+
*
235+
* When possible, it is preferrable to use one of the specialized variants of this predicate, such as `getMember`.
234236
*/
235237
cached
236-
Node getArrayElement() {
237-
exists(string s, int n |
238-
result = this.getMember(s) and
239-
s.toInt() = n and
240-
n.toString() = s and // ensure 's' is the canonical integer representation
241-
n >= 0
242-
)
243-
or
244-
result = this.getMember(DataFlow::PseudoProperties::arrayElement())
245-
or
246-
result = this.getUnknownMember()
238+
Node getContent(DataFlow::Content content) {
239+
// This predicate is currently not 'inline_late' because 'content' can be an input or output
240+
Stages::ApiStage::ref() and
241+
result = this.getASuccessor(Label::content(content))
247242
}
248243

244+
/**
245+
* Gets a representative for the `contents` of this value.
246+
*/
247+
bindingset[this, contents]
248+
pragma[inline_late]
249+
Node getContents(DataFlow::ContentSet contents) {
250+
// We always use getAStoreContent when generating content edges, and we always use getAReadContent when querying the graph.
251+
result = this.getContent(contents.getAReadContent())
252+
}
253+
254+
/**
255+
* Gets a node representing an arbitrary array element in the array represented by this node.
256+
*/
257+
cached
258+
Node getArrayElement() { result = this.getContents(DataFlow::ContentSet::arrayElement()) }
259+
249260
/**
250261
* Gets a node representing a member of this API component where the name of the member may
251262
* or may not be known statically.

0 commit comments

Comments
 (0)