Skip to content

Commit b1bf7f9

Browse files
committed
introduce pseudoProperty helper predicates
1 parent 5984014 commit b1bf7f9

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

javascript/ql/src/semmle/javascript/dataflow/Configuration.qll

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -576,26 +576,32 @@ abstract class AdditionalFlowStep extends DataFlow::Node {
576576

577577
/**
578578
* A collection of pseudo-properties that are used in multiple files.
579-
*
580-
* A pseudo-property represents the location where some value is stored in an object.
581-
*
579+
*
580+
* A pseudo-property represents the location where some value is stored in an object.
581+
*
582582
* For use with load/store steps in `DataFlow::AdditionalFlowStep` and TypeTracking.
583583
*/
584584
module PseudoProperties {
585+
bindingset[s]
586+
private string pseudoProperty(string s) { result = "$" + s + "$" }
587+
588+
bindingset[s, v]
589+
private string pseudoProperty(string s, string v) { result = "$" + s + "|" + v + "$" }
590+
585591
/**
586592
* Gets a pseudo-property for the location of elements in a `Set`
587593
*/
588-
string setElement() { result = "$setElement$" }
594+
string setElement() { result = pseudoProperty("setElement") }
589595

590596
/**
591597
* Gets a pseudo-property for the location of elements in a JavaScript iterator.
592598
*/
593-
string iteratorElement() { result = "$iteratorElement$" }
599+
string iteratorElement() { result = pseudoProperty("iteratorElement") }
594600

595601
/**
596602
* Gets a pseudo-property for the location of elements in an `Array`.
597603
*/
598-
string arrayElement() { result = "$arrayElement$" }
604+
string arrayElement() { result = pseudoProperty("arrayElement") }
599605

600606
/**
601607
* Gets a pseudo-property for the location of elements in some array-like object. (Set, Array, or Iterator).
@@ -605,15 +611,15 @@ module PseudoProperties {
605611
/**
606612
* Gets a pseudo-property for the location of map values, where the key is unknown.
607613
*/
608-
string mapValueUnknownKey() { result = "$UnknownMapValue$" }
614+
string mapValueUnknownKey() { result = pseudoProperty("unknownMapValue") }
609615

610616
/**
611617
* Gets a pseudo-property for the location of a map value where the key is `key`.
612618
* The string value of the `key` is encoded in the result, and there is only a result if the string value of `key` is known.
613619
*/
614620
pragma[inline]
615621
string mapValueKnownKey(DataFlow::Node key) {
616-
exists(string s | key.mayHaveStringValue(s) | result = "$mapValue|" + s + "$")
622+
result = pseudoProperty("mapValue", any(string s | key.mayHaveStringValue(s)))
617623
}
618624

619625
/**

0 commit comments

Comments
 (0)