Class NodejsRequireTargetSelector
java.lang.Object
com.ibm.wala.cast.js.nodejs.NodejsRequireTargetSelector
- All Implemented Interfaces:
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 Summary
-
Method Summary
Modifier and TypeMethodDescriptiongetCalleeTarget
(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.static SourceFileModule
Implements the Nodejs require.resolve algorithm, see Node.js documentationvoid
-
Constructor Details
-
NodejsRequireTargetSelector
-
-
Method Details
-
setCallGraphBuilder
-
getCalleeTarget
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 interfaceMethodTargetSelector
- Parameters:
caller
- the GCNode in the call graph containing the callsite
- the call site reference of the call sitereceiver
- the type of the target object or null- Returns:
- the method to be called.
-
resolve
Implements the Nodejs require.resolve algorithm, see Node.js documentationrequire(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 algorithmtarget
- X in the pseudo algorithm- Throws:
IOException
-