Correlation finder now handles both HTML files and raw JS files as
input, doesn't use WebPageLoaderFactory to create CAst anymore.
This commit is contained in:
parent
3d974b8313
commit
3adaaf50ee
|
@ -20,11 +20,9 @@ import java.util.Properties;
|
|||
import junit.framework.Assert;
|
||||
|
||||
import com.ibm.wala.cast.ir.translator.AstTranslator;
|
||||
import com.ibm.wala.cast.js.ipa.callgraph.PropertyNameContextSelector;
|
||||
import com.ibm.wala.cast.js.ipa.callgraph.JSCFABuilder;
|
||||
import com.ibm.wala.cast.js.ipa.callgraph.JavaScriptFunctionDotCallTargetSelector;
|
||||
import com.ibm.wala.cast.js.ipa.callgraph.RecursionCheckContextSelector;
|
||||
import com.ibm.wala.cast.js.ipa.callgraph.correlations.extraction.CorrelatedPairExtractorFactory;
|
||||
import com.ibm.wala.cast.js.test.JSCallGraphBuilderUtil;
|
||||
import com.ibm.wala.cast.js.test.JSCallGraphBuilderUtil.CGBuilderType;
|
||||
import com.ibm.wala.cast.js.translator.CAstRhinoTranslatorFactory;
|
||||
|
|
|
@ -15,7 +15,6 @@ import java.io.IOException;
|
|||
|
||||
import com.ibm.wala.cast.ir.translator.TranslatorToCAst.Error;
|
||||
import com.ibm.wala.cast.js.ipa.callgraph.correlations.CorrelationFinder;
|
||||
import com.ibm.wala.cast.js.translator.CAstRhinoTranslatorFactory;
|
||||
import com.ibm.wala.cast.js.translator.RhinoToAstTranslator;
|
||||
import com.ibm.wala.cast.tree.CAstEntity;
|
||||
import com.ibm.wala.cast.tree.impl.CAstImpl;
|
||||
|
@ -23,7 +22,7 @@ import com.ibm.wala.classLoader.SourceModule;
|
|||
|
||||
public class TestCorrelatedPairExtractionRhino extends TestCorrelatedPairExtraction {
|
||||
protected CorrelationFinder makeCorrelationFinder() {
|
||||
return new CorrelationFinder(new CAstRhinoTranslatorFactory());
|
||||
return new CorrelationFinder();
|
||||
}
|
||||
|
||||
protected CAstEntity parseJS(CAstImpl ast, SourceModule module) throws IOException {
|
||||
|
|
|
@ -161,9 +161,8 @@ public class TestRhinoSourceMap {
|
|||
sources.put(assertion[0], assertion[1]);
|
||||
}
|
||||
|
||||
URL script = TestRhinoSourceMap.class.getClassLoader().getResource(fileName);
|
||||
JavaScriptLoaderFactory loaders = makeLoaders(null);
|
||||
AnalysisScope scope = makeScriptScope(script, "tests", fileName, loaders);
|
||||
AnalysisScope scope = makeScriptScope("tests", fileName, loaders);
|
||||
IClassHierarchy cha = makeHierarchy(scope, loaders);
|
||||
for(IClass cls : cha) {
|
||||
if (cls.getName().toString().contains(fileName)) {
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
function extend(dest, src) {
|
||||
for(var p in src)
|
||||
dest[p] = src[p];
|
||||
}
|
||||
|
||||
var obj = {};
|
||||
extend(obj, {
|
||||
foo: function foo() {},
|
||||
bar: function bar() {}
|
||||
});
|
||||
obj.bar();
|
|
@ -95,7 +95,7 @@ public class JSCallGraphBuilderUtil extends com.ibm.wala.cast.js.ipa.callgraph.J
|
|||
|
||||
public static JSCFABuilder makeScriptCGBuilder(String dir, String name, CGBuilderType builderType) throws IOException, WalaException {
|
||||
URL script = getURLforFile(dir, name);
|
||||
CAstRewriterFactory preprocessor = builderType.extractCorrelatedPairs ? new CorrelatedPairExtractorFactory(translatorFactory, script) : null;
|
||||
CAstRewriterFactory preprocessor = builderType.extractCorrelatedPairs ? new CorrelatedPairExtractorFactory(script) : null;
|
||||
JavaScriptLoaderFactory loaders = JSCallGraphUtil.makeLoaders(preprocessor);
|
||||
|
||||
AnalysisScope scope = makeScriptScope(script, dir, name, loaders);
|
||||
|
@ -103,7 +103,7 @@ public class JSCallGraphBuilderUtil extends com.ibm.wala.cast.js.ipa.callgraph.J
|
|||
return makeCG(loaders, scope, builderType, AstIRFactory.makeDefaultFactory());
|
||||
}
|
||||
|
||||
private static URL getURLforFile(String dir, String name) {
|
||||
public static URL getURLforFile(String dir, String name) {
|
||||
URL script = JSCallGraphBuilderUtil.class.getClassLoader().getResource(dir + File.separator + name);
|
||||
if (script == null) {
|
||||
script = JSCallGraphBuilderUtil.class.getClassLoader().getResource(dir + "/" + name);
|
||||
|
@ -145,7 +145,7 @@ public class JSCallGraphBuilderUtil extends com.ibm.wala.cast.js.ipa.callgraph.J
|
|||
|
||||
public static CallGraph makeScriptCG(SourceModule[] scripts, CGBuilderType builderType, IRFactory<IMethod> irFactory) throws IOException, IllegalArgumentException,
|
||||
CancelException, WalaException {
|
||||
CAstRewriterFactory preprocessor = builderType.extractCorrelatedPairs ? new CorrelatedPairExtractorFactory(translatorFactory, scripts) : null;
|
||||
CAstRewriterFactory preprocessor = builderType.extractCorrelatedPairs ? new CorrelatedPairExtractorFactory(scripts) : null;
|
||||
PropagationCallGraphBuilder b = makeCGBuilder(makeLoaders(preprocessor), scripts, builderType, irFactory);
|
||||
CallGraph CG = b.makeCallGraph(b.getOptions());
|
||||
// dumpCG(b.getPointerAnalysis(), CG);
|
||||
|
@ -160,7 +160,7 @@ public class JSCallGraphBuilderUtil extends com.ibm.wala.cast.js.ipa.callgraph.J
|
|||
JavaScriptLoader.addBootstrapFile(WebUtil.preamble);
|
||||
SourceModule[] scripts;
|
||||
IRFactory<IMethod> irFactory = AstIRFactory.makeDefaultFactory();
|
||||
CAstRewriterFactory preprocessor = builderType.extractCorrelatedPairs ? new CorrelatedPairExtractorFactory(translatorFactory, url) : null;
|
||||
CAstRewriterFactory preprocessor = builderType.extractCorrelatedPairs ? new CorrelatedPairExtractorFactory(url) : null;
|
||||
JavaScriptLoaderFactory loaders = new WebPageLoaderFactory(translatorFactory, preprocessor);
|
||||
try {
|
||||
Set<MappedSourceModule> script = WebUtil.extractScriptFromHTML(url).fst;
|
||||
|
|
|
@ -655,7 +655,7 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
|
|||
|
||||
private static final Object[][] assertionsForExtend = new Object[][] {
|
||||
new Object[] { ROOT, new String[] { "tests/extend.js" } },
|
||||
new Object[] { "tests/extend.js", new String[] { "suffix:foo", "!suffix:bar" } }
|
||||
new Object[] { "tests/extend.js", new String[] { "suffix:bar", "!suffix:foo" } }
|
||||
};
|
||||
|
||||
@Test
|
||||
|
|
|
@ -30,10 +30,10 @@ import com.ibm.wala.cast.ir.ssa.AbstractReflectiveGet;
|
|||
import com.ibm.wala.cast.ir.ssa.AbstractReflectivePut;
|
||||
import com.ibm.wala.cast.ir.ssa.AstIRFactory;
|
||||
import com.ibm.wala.cast.ir.translator.TranslatorToCAst.Error;
|
||||
import com.ibm.wala.cast.js.html.WebPageLoaderFactory;
|
||||
import com.ibm.wala.cast.js.html.WebUtil;
|
||||
import com.ibm.wala.cast.js.ipa.callgraph.JSCallGraphUtil;
|
||||
import com.ibm.wala.cast.js.loader.JavaScriptLoader;
|
||||
import com.ibm.wala.cast.js.translator.JavaScriptTranslatorFactory;
|
||||
import com.ibm.wala.cast.js.loader.JavaScriptLoaderFactory;
|
||||
import com.ibm.wala.cast.js.util.Util;
|
||||
import com.ibm.wala.cast.loader.AstMethod;
|
||||
import com.ibm.wala.cast.loader.AstMethod.LexicalInformation;
|
||||
|
@ -41,6 +41,7 @@ import com.ibm.wala.cast.tree.CAstSourcePositionMap.Position;
|
|||
import com.ibm.wala.classLoader.IClass;
|
||||
import com.ibm.wala.classLoader.IMethod;
|
||||
import com.ibm.wala.classLoader.SourceModule;
|
||||
import com.ibm.wala.classLoader.SourceURLModule;
|
||||
import com.ibm.wala.ipa.callgraph.impl.Everywhere;
|
||||
import com.ibm.wala.ipa.cha.ClassHierarchy;
|
||||
import com.ibm.wala.ipa.cha.ClassHierarchyException;
|
||||
|
@ -77,8 +78,6 @@ public class CorrelationFinder {
|
|||
private final static boolean TRACK_ESCAPES = true;
|
||||
private final static boolean IGNORE_NUMERIC_INDICES = false;
|
||||
|
||||
private final JavaScriptTranslatorFactory translatorFactory;
|
||||
|
||||
public static CorrelationSummary findCorrelatedAccesses(IMethod method, IR ir) {
|
||||
AstMethod astMethod = (AstMethod)method;
|
||||
DefUse du = new DefUse(ir);
|
||||
|
@ -249,12 +248,17 @@ public class CorrelationFinder {
|
|||
}
|
||||
|
||||
public Map<IMethod, CorrelationSummary> findCorrelatedAccesses(URL url) throws IOException, ClassHierarchyException {
|
||||
JavaScriptLoader.addBootstrapFile(WebUtil.preamble);
|
||||
Set<? extends SourceModule> scripts = null;
|
||||
try {
|
||||
scripts = WebUtil.extractScriptFromHTML(url).fst;
|
||||
} catch (Error e) {
|
||||
assert false : e.warning;
|
||||
if(url.getPath().endsWith(".js")) {
|
||||
scripts = Collections.singleton(new SourceURLModule(url));
|
||||
} else {
|
||||
JavaScriptLoader.addBootstrapFile(WebUtil.preamble);
|
||||
try {
|
||||
scripts = WebUtil.extractScriptFromHTML(url).fst;
|
||||
} catch (Error e) {
|
||||
e.printStackTrace();
|
||||
assert false : e.warning;
|
||||
}
|
||||
}
|
||||
Map<IMethod, CorrelationSummary> summaries = findCorrelatedAccesses(scripts);
|
||||
return summaries;
|
||||
|
@ -267,7 +271,7 @@ public class CorrelationFinder {
|
|||
|
||||
public Map<IMethod, CorrelationSummary> findCorrelatedAccesses(SourceModule[] scripts_array) throws IOException,
|
||||
ClassHierarchyException {
|
||||
WebPageLoaderFactory loaders = new WebPageLoaderFactory(translatorFactory);
|
||||
JavaScriptLoaderFactory loaders = JSCallGraphUtil.makeLoaders(null);
|
||||
CAstAnalysisScope scope = new CAstAnalysisScope(scripts_array, loaders, Collections.singleton(JavaScriptLoader.JS));
|
||||
IClassHierarchy cha = ClassHierarchy.make(scope, loaders, JavaScriptLoader.JS);
|
||||
try {
|
||||
|
@ -281,15 +285,12 @@ public class CorrelationFinder {
|
|||
for(IClass klass : cha) {
|
||||
for(IMethod method : klass.getAllMethods()) {
|
||||
IR ir = factory.makeIR(method, Everywhere.EVERYWHERE, SSAOptions.defaultOptions());
|
||||
if(method.toString().endsWith("__WINDOW_MAIN__>"))
|
||||
System.out.println(ir);
|
||||
CorrelationSummary summary = findCorrelatedAccesses(method, ir);
|
||||
if(!summary.getCorrelations().isEmpty())
|
||||
correlations.put(method, summary);
|
||||
}
|
||||
}
|
||||
|
||||
printCorrelatedAccesses(correlations);
|
||||
return correlations;
|
||||
}
|
||||
|
||||
|
@ -304,8 +305,4 @@ public class CorrelationFinder {
|
|||
return new URL(src);
|
||||
}
|
||||
}
|
||||
|
||||
public CorrelationFinder(JavaScriptTranslatorFactory translatorFactory) {
|
||||
this.translatorFactory = translatorFactory;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,16 +30,16 @@ import com.ibm.wala.ipa.cha.ClassHierarchyException;
|
|||
public class CorrelatedPairExtractorFactory implements CAstRewriterFactory<NodePos, NoKey> {
|
||||
private final Map<IMethod, CorrelationSummary> summaries;
|
||||
|
||||
public CorrelatedPairExtractorFactory(JavaScriptTranslatorFactory translatorFactory, URL entryPoint) throws ClassHierarchyException, IOException {
|
||||
this(new CorrelationFinder(translatorFactory).findCorrelatedAccesses(entryPoint));
|
||||
public CorrelatedPairExtractorFactory(URL entryPoint) throws ClassHierarchyException, IOException {
|
||||
this(new CorrelationFinder().findCorrelatedAccesses(entryPoint));
|
||||
}
|
||||
|
||||
public CorrelatedPairExtractorFactory(JavaScriptTranslatorFactory translatorFactory, Collection<? extends SourceModule> scripts) throws ClassHierarchyException, IOException {
|
||||
this(new CorrelationFinder(translatorFactory).findCorrelatedAccesses(scripts));
|
||||
public CorrelatedPairExtractorFactory(Collection<? extends SourceModule> scripts) throws ClassHierarchyException, IOException {
|
||||
this(new CorrelationFinder().findCorrelatedAccesses(scripts));
|
||||
}
|
||||
|
||||
public CorrelatedPairExtractorFactory(JavaScriptTranslatorFactory translatorFactory, SourceModule[] scripts) throws ClassHierarchyException, IOException {
|
||||
this(new CorrelationFinder(translatorFactory).findCorrelatedAccesses(scripts));
|
||||
public CorrelatedPairExtractorFactory(SourceModule[] scripts) throws ClassHierarchyException, IOException {
|
||||
this(new CorrelationFinder().findCorrelatedAccesses(scripts));
|
||||
}
|
||||
|
||||
public CorrelatedPairExtractorFactory(Map<IMethod, CorrelationSummary> summaries) {
|
||||
|
|
Loading…
Reference in New Issue