Skip to content

Clarification Needed on Nodes in JavaScript Call Graph Using Field-Based Algorithm #1375

Open
@flyboss

Description

@flyboss

Issue Description:

I am currently facing a challenge while generating a call graph for a JavaScript file using WALA (the T.J. Watson Libraries for Analysis). In the generated call graph, I observe the inclusion of certain nodes that do not correspond to call sites, and these nodes do not have any callees associated with them.

Test JavaScript Code:

var a = [];
var b = {};

Java code

import com.ibm.wala.cast.js.callgraph.fieldbased.FieldBasedCallGraphBuilder;
import com.ibm.wala.cast.js.translator.CAstRhinoTranslatorFactory;
import com.ibm.wala.cast.js.util.CallGraph2JSON;
import com.ibm.wala.cast.js.util.FieldBasedCGUtil;
import com.ibm.wala.ipa.callgraph.CallGraph;
import com.ibm.wala.util.CancelException;
import com.ibm.wala.util.NullProgressMonitor;
import com.ibm.wala.util.WalaException;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;

public class tmp {
    public static void main(String[] args) throws WalaException, CancelException, IOException {
        Path path = Paths.get("hello.js");
        FieldBasedCGUtil f = new FieldBasedCGUtil(new CAstRhinoTranslatorFactory());
        FieldBasedCallGraphBuilder.CallGraphResult results = f.buildScriptDirCG(path, FieldBasedCGUtil.BuilderType.OPTIMISTIC_WORKLIST,new NullProgressMonitor(),false);
        CallGraph CG = results.getCallGraph();

        try {
            FileWriter myWriter1 = new FileWriter(new File("SCG_OPT.json"));
            myWriter1.write((new CallGraph2JSON(false,true)).serialize(CG));
            myWriter1.close();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}

Output using field-based(OPTIMISTIC_WORKLIST) Algorithm:

{
  "hello.js@1:0-23": {
    "hello.js@1:8-10": [],
    "hello.js@2:20-22": []
  }
}

Inquiry:

Is there a way to filter out or exclude these non-call-site nodes from the call graph? These nodes, which do not represent function invocations, are adding unnecessary complexity to the call graph and do not serve any purpose for my analysis. I am looking for advice on how to adjust the settings or modify WALA to prevent these nodes from being included in the call graph. Any recommendations or insights on this matter would be highly appreciated.

Thank you for your assistance!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions