Class NodejsRequireTargetSelector

java.lang.Object
com.ibm.wala.cast.js.nodejs.NodejsRequireTargetSelector
All Implemented Interfaces:
MethodTargetSelector

public class NodejsRequireTargetSelector extends Object implements MethodTargetSelector
This class is used by WALA internals to resolve to what functions a call could potentially invoke.
Author:
Brian Pfretzschner <brian.pfretzschner@gmail.com>
  • Constructor Details

  • Method Details

    • setCallGraphBuilder

      public void setCallGraphBuilder(PropagationCallGraphBuilder builder)
    • getCalleeTarget

      public IMethod getCalleeTarget(CGNode caller, CallSiteReference site, IClass receiver)
      Basic idea: If the called method is named "__WALA__require", it is most likely the require-function mock from the module-wrapper. To figure out what file shall be required, pointer analysis is used to identify strings that can flow into the require call. That file is than loaded, wrapped into the module wrapper and returned as method that will be invoked. Therefore, there will never be an call graph edge to the require function call, the require function is replaced by the file that is included through the require call.

      Given a calling node, a call site and (optionally) a dispatch type, return the target method to be called.

      Specified by:
      getCalleeTarget in interface MethodTargetSelector
      Parameters:
      caller - the GCNode in the call graph containing the call
      site - the call site reference of the call site
      receiver - the type of the target object or null
      Returns:
      the method to be called.
    • resolve

      public static SourceFileModule resolve(File rootDir, File dir, String target) throws IOException
      Implements the Nodejs require.resolve algorithm, see Node.js documentation

      require(X) from module at path Y 1. If X is a core module, a. return the core module b. STOP 2. If X begins with './' or '/' or '../' a. LOAD_AS_FILE(Y + X) b. LOAD_AS_DIRECTORY(Y + X) 3. LOAD_NODE_MODULES(X, dirname(Y)) 4. THROW "not found"

      Parameters:
      dir - Y in the pseudo algorithm
      target - X in the pseudo algorithm
      Throws:
      IOException