@@ -184,23 +184,38 @@ class CallCfgNode extends CfgNode, LocalSourceNode {
184184 * A data-flow node corresponding to a method call, that is `foo.bar(...)`.
185185 *
186186 * Also covers the case where the method lookup is done separately from the call itself, as in
187- * `temp = foo.bar; temp(...)`.
187+ * `temp = foo.bar; temp(...)`. Note that this is only tracked through local scope.
188188 */
189189class MethodCallNode extends CallCfgNode {
190190 AttrRead method_lookup ;
191191
192192 MethodCallNode ( ) { method_lookup = this .getFunction ( ) .getALocalSource ( ) }
193193
194- /** Gets the name of the method being invoked (the `bar` in `foo.bar(...)`, if it can be determined. */
194+ /**
195+ * Gets the name of the method being invoked (the `bar` in `foo.bar(...)`) if it can be determined.
196+ *
197+ * Note that this method may have multiple results if a single call node represents calls to
198+ * multiple different objects and methods. If you want to link up objects and method names
199+ * accurately, use the `calls` method instead.
200+ */
195201 string getMethodName ( ) { result = method_lookup .getAttributeName ( ) }
196202
197- /** Gets the data-flow node corresponding to the receiver of this call. That is, the `foo` in `foo.bar(...)`. */
198- Node getReceiver ( ) { result = method_lookup .getObject ( ) }
199-
200- /** Holds if this data-flow node calls method `methodName` on receiver node `receiver`. */
201- predicate calls ( Node receiver , string methodName ) {
202- receiver = this .getReceiver ( ) and
203- methodName = this .getMethodName ( )
203+ /**
204+ * Gets the data-flow node corresponding to the object receiving this call. That is, the `foo` in
205+ * `foo.bar(...)`.
206+ *
207+ * Note that this method may have multiple results if a single call node represents calls to
208+ * multiple different objects and methods. If you want to link up objects and method names
209+ * accurately, use the `calls` method instead.
210+ */
211+ Node getObject ( ) { result = method_lookup .getObject ( ) }
212+
213+ /** Holds if this data-flow node calls method `methodName` on the object node `object`. */
214+ predicate calls ( Node object , string methodName ) {
215+ // As `getObject` and `getMethodName` may both have multiple results, we must look up the object
216+ // and method name directly on `method_lookup`.
217+ object = method_lookup .getObject ( ) and
218+ methodName = method_lookup .getAttributeName ( )
204219 }
205220}
206221
0 commit comments