CodeQL library for JavaScript
Search

Predicate DataFlow::functionOneWayForwardingStep

Holds if the function in succ forwards all its arguments to a call to pred. This can thus be seen as a step pred -> succ used for tracking function values through “wrapper functions”, since the succ function partially replicates behavior of pred.

This is similar to functionForwardingStep except the innermost forwarding call does not need flow to the return value; this can be useful for tracking callback-style functions where the result tends to be unused.

Examples:

function f(x, callback) {
  g(x, callback); // step: g -> f
}

function doExec(x, callback) {
  console.log(x);
  exec(x, callback); // step: exec -> doExec
}

function doEither(x, y) {
  if (x > y) {
    return foo(x, y); // step: foo -> doEither
  } else {
    return bar(x, y); // step: bar -> doEither
  }
}

function wrapWithLogging(f) {
  return (x) => {
    console.log(x);
    return f(x); // step: f -> anonymous function
  }
}
wrapWithLogging(g); // step: g -> wrapWithLogging(g)

Import path

import javascript
predicate functionOneWayForwardingStep(Node pred, Node succ)