Variety of changes to JS front end.

- crash fixes
- small enhancements to prologue and preamble
- tighter handling of timeouts during CG construction
This commit is contained in:
Manu Sridharan 2013-04-09 15:47:22 -07:00
parent 1d06b2f764
commit 11c6619c7f
52 changed files with 51333 additions and 296 deletions

View File

@ -182,7 +182,7 @@ public abstract class JavaSourceLoaderImpl extends ClassLoaderImpl {
private JavaField(CAstEntity fieldEntity, IClassLoader loader, IClass declaringClass) {
super(FieldReference.findOrCreate(declaringClass.getReference(), Atom.findOrCreateUnicodeAtom(fieldEntity.getName()),
TypeReference.findOrCreate(loader.getReference(), TypeName.string2TypeName(fieldEntity.getType().getName()))),
fieldEntity.getQualifiers(), declaringClass, declaringClass.getClassHierarchy());
fieldEntity.getQualifiers(), declaringClass, declaringClass.getClassHierarchy(), null);
}
}
@ -200,14 +200,14 @@ public abstract class JavaSourceLoaderImpl extends ClassLoaderImpl {
public JavaEntityMethod(CAstEntity methodEntity, IClass owner, AbstractCFG cfg, SymbolTable symtab, boolean hasCatchBlock,
TypeReference[][] catchTypes, boolean hasMonitorOp, AstLexicalInformation lexicalInfo, DebuggingInformation debugInfo) {
super(owner, methodEntity.getQualifiers(), cfg, symtab, MethodReference.findOrCreate(owner.getReference(), Util
.methodEntityToSelector(methodEntity)), hasCatchBlock, catchTypes, hasMonitorOp, lexicalInfo, debugInfo);
.methodEntityToSelector(methodEntity)), hasCatchBlock, catchTypes, hasMonitorOp, lexicalInfo, debugInfo, null);
this.parameterTypes = computeParameterTypes(methodEntity);
this.exceptionTypes = computeExceptionTypes(methodEntity);
}
public JavaEntityMethod(CAstEntity methodEntity, IClass owner) {
super(owner, methodEntity.getQualifiers(), MethodReference.findOrCreate(owner.getReference(), Util
.methodEntityToSelector(methodEntity)));
.methodEntityToSelector(methodEntity)), null);
this.parameterTypes = computeParameterTypes(methodEntity);
this.exceptionTypes = computeExceptionTypes(methodEntity);
}

View File

@ -13,6 +13,7 @@ package com.ibm.wala.cast.js.test;
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;
@ -27,7 +28,13 @@ public class TestCorrelatedPairExtractionRhino extends TestCorrelatedPairExtract
protected CAstEntity parseJS(CAstImpl ast, SourceModule module) throws IOException {
RhinoToAstTranslator translator = new RhinoToAstTranslator(ast, module, module.getName(), false);
CAstEntity entity = translator.translateToCAst();
CAstEntity entity = null;
try {
entity = translator.translateToCAst();
} catch (Error e) {
e.printStackTrace();
assert false;
}
return entity;
}
}

View File

@ -13,6 +13,7 @@ package com.ibm.wala.cast.js.test;
import java.io.IOException;
import com.ibm.wala.cast.ir.translator.TranslatorToCAst.Error;
import com.ibm.wala.cast.js.translator.RhinoToAstTranslator;
import com.ibm.wala.cast.tree.CAstEntity;
import com.ibm.wala.cast.tree.impl.CAstImpl;
@ -21,7 +22,13 @@ import com.ibm.wala.classLoader.SourceModule;
public class TestForInBodyExtractionRhino extends TestForInBodyExtraction {
protected CAstEntity parseJS(CAstImpl ast, SourceModule module) throws IOException {
RhinoToAstTranslator translator = new RhinoToAstTranslator(ast, module, module.getName(), false);
CAstEntity entity = translator.translateToCAst();
CAstEntity entity = null;
try {
entity = translator.translateToCAst();
} catch (Error e) {
e.printStackTrace();
assert false;
}
return entity;
}
}

View File

@ -17,8 +17,11 @@ import org.junit.Test;
import com.ibm.wala.cast.js.ipa.callgraph.JSCFABuilder;
import com.ibm.wala.cast.js.translator.CAstRhinoTranslatorFactory;
import com.ibm.wala.cast.js.util.Util;
import com.ibm.wala.ipa.callgraph.propagation.PointerAnalysis;
import com.ibm.wala.ipa.callgraph.propagation.PropagationCallGraphBuilder;
import com.ibm.wala.util.CancelException;
import com.ibm.wala.util.WalaException;
public class TestSimpleCallGraphShapeRhino extends TestSimpleCallGraphShape {
@ -32,7 +35,7 @@ public class TestSimpleCallGraphShapeRhino extends TestSimpleCallGraphShape {
}
@Test
public void test214631() throws IOException, IllegalArgumentException, CancelException {
public void test214631() throws IOException, IllegalArgumentException, CancelException, WalaException {
JSCFABuilder b = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "214631.js");
b.makeCallGraph(b.getOptions());
PointerAnalysis PA = b.getPointerAnalysis();
@ -41,33 +44,41 @@ public class TestSimpleCallGraphShapeRhino extends TestSimpleCallGraphShape {
}
@Test
public void testRewriterDoesNotChangeLablesBug() throws IOException, IllegalArgumentException, CancelException {
public void testRewriterDoesNotChangeLablesBug() throws IOException, IllegalArgumentException, CancelException, WalaException {
JSCallGraphBuilderUtil.makeScriptCG("tests", "rewrite_does_not_change_lables_bug.js");
// all we need is for it to finish building CG successfully.
}
@Test
public void testRepr() throws IllegalArgumentException, IOException, CancelException {
public void testRepr() throws IllegalArgumentException, IOException, CancelException, WalaException {
JSCallGraphBuilderUtil.makeScriptCG("tests", "repr.js");
}
@Test
public void testTranslateToCAstCrash1() throws IllegalArgumentException, IOException, CancelException {
public void testTranslateToCAstCrash1() throws IllegalArgumentException, IOException, CancelException, WalaException {
JSCallGraphBuilderUtil.makeScriptCG("tests", "rhino_crash1.js");
}
@Test
public void testTranslateToCAstCrash2() throws IllegalArgumentException, IOException, CancelException {
public void testTranslateToCAstCrash2() throws IllegalArgumentException, IOException, CancelException, WalaException {
JSCallGraphBuilderUtil.makeScriptCG("tests", "rhino_crash2.js");
}
@Test
public void testTranslateToCAstCrash3() throws IllegalArgumentException, IOException, CancelException {
public void testTranslateToCAstCrash3() throws IllegalArgumentException, IOException, CancelException, WalaException {
JSCallGraphBuilderUtil.makeScriptCG("tests", "rhino_crash3.js");
}
@Test
public void testNonLoopBreakLabel() throws IllegalArgumentException, IOException, CancelException {
public void testNonLoopBreakLabel() throws IllegalArgumentException, IOException, CancelException, WalaException {
JSCallGraphBuilderUtil.makeScriptCG("tests", "non_loop_break.js");
}
@Test(expected = WalaException.class)
public void testParseError() throws IllegalArgumentException, IOException, CancelException, WalaException {
PropagationCallGraphBuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "portal-example-simple.html");
B.makeCallGraph(B.getOptions());
Util.checkForFrontEndErrors(B.getClassHierarchy());
}
}

View File

@ -20,9 +20,12 @@ import com.ibm.wala.cast.js.html.IHtmlParser;
import com.ibm.wala.cast.js.html.IHtmlParserFactory;
import com.ibm.wala.cast.js.html.JSSourceExtractor;
import com.ibm.wala.cast.js.html.WebUtil;
import com.ibm.wala.cast.js.ipa.callgraph.JSCFABuilder;
import com.ibm.wala.cast.js.translator.CAstRhinoTranslatorFactory;
import com.ibm.wala.cast.js.util.Util;
import com.ibm.wala.ipa.callgraph.CallGraph;
import com.ibm.wala.util.CancelException;
import com.ibm.wala.util.WalaException;
public abstract class TestSimplePageCallGraphShapeRhino extends TestSimplePageCallGraphShape {
@ -31,12 +34,20 @@ public abstract class TestSimplePageCallGraphShapeRhino extends TestSimplePageCa
new Object[] { "page3.html", new String[] { "page3.html/__WINDOW_MAIN__" } }
};
@Test public void testPage3() throws IOException, IllegalArgumentException, CancelException {
@Test public void testPage3() throws IOException, IllegalArgumentException, CancelException, WalaException {
URL url = getClass().getClassLoader().getResource("pages/page3.html");
CallGraph CG = JSCallGraphBuilderUtil.makeHTMLCG(url);
verifyGraphAssertions(CG, assertionsForPage3);
}
@Test(expected = WalaException.class)
public void testJSParseError() throws IOException, IllegalArgumentException, CancelException, WalaException {
URL url = getClass().getClassLoader().getResource("pages/garbage2.html");
JSCFABuilder B = JSCallGraphBuilderUtil.makeHTMLCGBuilder(url);
B.makeCallGraph(B.getOptions());
Util.checkForFrontEndErrors(B.getClassHierarchy());
}
public static void main(String[] args) {
justThisTest(TestSimplePageCallGraphShapeRhino.class);
}

View File

@ -7,18 +7,28 @@ import org.junit.Test;
import com.ibm.wala.cast.js.html.IHtmlParser;
import com.ibm.wala.cast.js.html.jericho.JerichoHtmlParser;
import com.ibm.wala.cast.js.ipa.callgraph.JSCFABuilder;
import com.ibm.wala.cast.js.util.Util;
import com.ibm.wala.ipa.callgraph.CallGraph;
import com.ibm.wala.util.CancelException;
import com.ibm.wala.util.WalaException;
public class TestSimplePageCallGraphShapeRhinoJericho extends TestSimplePageCallGraphShapeRhino {
@Test public void testCrawl() throws IOException, IllegalArgumentException, CancelException {
@Test public void testCrawl() throws IOException, IllegalArgumentException, CancelException, WalaException {
URL url = getClass().getClassLoader().getResource("pages/crawl.html");
CallGraph CG = JSCallGraphBuilderUtil.makeHTMLCG(url);
verifyGraphAssertions(CG, null);
}
@Test public void testParseError() throws IOException, IllegalArgumentException, CancelException, WalaException {
URL url = getClass().getClassLoader().getResource("pages/garbage.html");
JSCFABuilder B = JSCallGraphBuilderUtil.makeHTMLCGBuilder(url);
B.makeCallGraph(B.getOptions());
Util.checkForFrontEndErrors(B.getClassHierarchy());
}
public static void main(String[] args) {
justThisTest(TestSimplePageCallGraphShapeRhinoJericho.class);
}

View File

@ -5,6 +5,7 @@ import java.net.URL;
import java.util.Set;
import com.ibm.wala.cast.ir.ssa.AstIRFactory;
import com.ibm.wala.cast.ir.translator.TranslatorToCAst.Error;
import com.ibm.wala.cast.js.html.DefaultSourceExtractor;
import com.ibm.wala.cast.js.html.DomLessSourceExtractor;
import com.ibm.wala.cast.js.html.IdentityUrlResolver;
@ -23,9 +24,10 @@ import com.ibm.wala.ipa.callgraph.CallGraph;
import com.ibm.wala.ipa.callgraph.propagation.PointerAnalysis;
import com.ibm.wala.ipa.cha.ClassHierarchyException;
import com.ibm.wala.util.CancelException;
import com.ibm.wala.util.WalaException;
public class JsViewerDriver extends JSCallGraphBuilderUtil {
public static void main(String args[]) throws ClassHierarchyException, IllegalArgumentException, IOException, CancelException {
public static void main(String args[]) throws ClassHierarchyException, IllegalArgumentException, IOException, CancelException, Error, WalaException {
if (args.length != 1){
System.out.println("Usage: <URL of html page to analyze>");
@ -51,7 +53,7 @@ public class JsViewerDriver extends JSCallGraphBuilderUtil {
}
private static SourceModule[] getSources(boolean domless, URL url)
throws IOException {
throws IOException, Error {
JSSourceExtractor sourceExtractor;
if (domless ){
sourceExtractor = new DomLessSourceExtractor();

View File

@ -40,7 +40,7 @@ public class CAstRhinoTranslator implements TranslatorToCAst {
rewriters.add(factory);
}
public CAstEntity translateToCAst() throws IOException {
public CAstEntity translateToCAst() throws IOException, Error {
String N;
if (M instanceof SourceFileModule) {
N = ((SourceFileModule) M).getClassName();

View File

@ -10,6 +10,7 @@
*****************************************************************************/
package com.ibm.wala.cast.js.translator;
import java.io.IOException;
import java.io.Reader;
import java.net.URL;
import java.util.ArrayList;
@ -20,6 +21,8 @@ import java.util.List;
import java.util.Map;
import org.mozilla.javascript.CompilerEnvirons;
import org.mozilla.javascript.ErrorReporter;
import org.mozilla.javascript.EvaluatorException;
import org.mozilla.javascript.Node;
import org.mozilla.javascript.Parser;
import org.mozilla.javascript.Token;
@ -83,8 +86,8 @@ import org.mozilla.javascript.ast.XmlPropRef;
import org.mozilla.javascript.ast.XmlRef;
import org.mozilla.javascript.ast.XmlString;
import org.mozilla.javascript.ast.Yield;
import org.mozilla.javascript.tools.ToolErrorReporter;
import com.ibm.wala.cast.ir.translator.TranslatorToCAst;
import com.ibm.wala.cast.ir.translator.TranslatorToCAst.DoLoopTranslator;
import com.ibm.wala.cast.js.html.MappedSourceModule;
import com.ibm.wala.cast.js.ipa.callgraph.JSSSAPropagationCallGraphBuilder;
@ -105,6 +108,7 @@ import com.ibm.wala.classLoader.SourceModule;
import com.ibm.wala.util.collections.EmptyIterator;
import com.ibm.wala.util.collections.HashMapFactory;
import com.ibm.wala.util.debug.Assertions;
import com.ibm.wala.util.warnings.Warning;
public class RhinoToAstTranslator {
@ -2248,9 +2252,32 @@ private CAstNode[] walkChildren(final Node n, WalkContext context) {
/**
* parse the JavaScript code using Rhino, and then translate the resulting AST
* to CAst
* @throws com.ibm.wala.cast.ir.translator.TranslatorToCAst.Error
*/
public CAstEntity translateToCAst() throws java.io.IOException {
ToolErrorReporter reporter = new ToolErrorReporter(true);
public CAstEntity translateToCAst() throws Error, IOException, com.ibm.wala.cast.ir.translator.TranslatorToCAst.Error {
class CAstErrorReporter implements ErrorReporter {
private Warning w = null;
public void error(final String arg0, final String arg1, final int arg2, final String arg3, int arg4) {
w = new Warning(Warning.SEVERE) {
@Override
public String getMsg() {
return arg0 + ": " + arg1 + "@" + arg2 + ": " + arg3;
}
};
}
public EvaluatorException runtimeError(String arg0, String arg1, int arg2, String arg3, int arg4) {
error(arg0, arg1, arg2, arg3, arg4);
return null;
}
public void warning(String arg0, String arg1, int arg2, String arg3, int arg4) {
// ignore warnings
}
};
CAstErrorReporter reporter = new CAstErrorReporter();
CompilerEnvirons compilerEnv = new CompilerEnvirons();
compilerEnv.setErrorReporter(reporter);
compilerEnv.setReservedKeywordAsIdentifier(true);
@ -2264,6 +2291,10 @@ private CAstNode[] walkChildren(final Node n, WalkContext context) {
AstRoot top = P.parse(sourceReader, scriptName, 1);
if (reporter.w != null) {
throw new TranslatorToCAst.Error(reporter.w);
}
final FunctionContext child = new ScriptContext(new RootContext(), top, top.getSourceName());
TranslatingVisitor tv = new TranslatingVisitor();
List<CAstNode> body = new ArrayList<CAstNode>();

View File

@ -0,0 +1,3 @@
#$
>>> <this is very <<buggy
<tag silly="this is not good

View File

@ -0,0 +1,5 @@
<HTML>
<SCRIPT language="javascript">
this is so not a valid JS program!
</SCRIPT>
</HTML>

View File

@ -0,0 +1,13 @@
function twoReturns(x) {
if (x != 0) {
return 1;
} else {
return 2;
}
if (x > 7) {
x++;
}
return -1;
}
twoReturns(7);

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1 @@
function a() {

View File

@ -19,6 +19,7 @@ import java.util.Set;
import junit.framework.Assert;
import com.ibm.wala.cast.ir.ssa.AstIRFactory;
import com.ibm.wala.cast.ir.translator.TranslatorToCAst.Error;
import com.ibm.wala.cast.js.html.MappedSourceModule;
import com.ibm.wala.cast.js.html.WebPageLoaderFactory;
import com.ibm.wala.cast.js.html.WebUtil;
@ -27,8 +28,10 @@ import com.ibm.wala.cast.js.ipa.callgraph.JSCFABuilder;
import com.ibm.wala.cast.js.ipa.callgraph.JSZeroOrOneXCFABuilder;
import com.ibm.wala.cast.js.loader.JavaScriptLoader;
import com.ibm.wala.cast.js.loader.JavaScriptLoaderFactory;
import com.ibm.wala.cast.loader.CAstAbstractLoader;
import com.ibm.wala.classLoader.SourceFileModule;
import com.ibm.wala.classLoader.SourceModule;
import com.ibm.wala.classLoader.SourceURLModule;
import com.ibm.wala.ipa.callgraph.AnalysisCache;
import com.ibm.wala.ipa.callgraph.AnalysisScope;
import com.ibm.wala.ipa.callgraph.CallGraph;
@ -39,6 +42,7 @@ import com.ibm.wala.ipa.cha.ClassHierarchyException;
import com.ibm.wala.ipa.cha.IClassHierarchy;
import com.ibm.wala.ssa.IRFactory;
import com.ibm.wala.util.CancelException;
import com.ibm.wala.util.WalaException;
/**
* TODO this class is a mess. rewrite.
@ -74,7 +78,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 {
public static JSCFABuilder makeScriptCGBuilder(String dir, String name, CGBuilderType builderType) throws IOException, WalaException {
JavaScriptLoaderFactory loaders = JSCallGraphBuilderUtil.makeLoaders();
AnalysisScope scope = makeScriptScope(dir, name, loaders);
@ -99,16 +103,16 @@ public class JSCallGraphBuilderUtil extends com.ibm.wala.cast.js.ipa.callgraph.J
return scope;
}
public static JSCFABuilder makeScriptCGBuilder(String dir, String name) throws IOException {
public static JSCFABuilder makeScriptCGBuilder(String dir, String name) throws IOException, WalaException {
return makeScriptCGBuilder(dir, name, CGBuilderType.ZERO_ONE_CFA);
}
public static CallGraph makeScriptCG(String dir, String name) throws IOException, IllegalArgumentException, CancelException {
public static CallGraph makeScriptCG(String dir, String name) throws IOException, IllegalArgumentException, CancelException, WalaException {
return makeScriptCG(dir, name, CGBuilderType.ZERO_ONE_CFA);
}
public static CallGraph makeScriptCG(String dir, String name, CGBuilderType builderType) throws IOException,
IllegalArgumentException, CancelException {
IllegalArgumentException, CancelException, WalaException {
PropagationCallGraphBuilder b = makeScriptCGBuilder(dir, name, builderType);
CallGraph CG = b.makeCallGraph(b.getOptions());
// dumpCG(b.getPointerAnalysis(), CG);
@ -116,26 +120,36 @@ public class JSCallGraphBuilderUtil extends com.ibm.wala.cast.js.ipa.callgraph.J
}
public static CallGraph makeScriptCG(SourceModule[] scripts, CGBuilderType builderType, IRFactory irFactory) throws IOException, IllegalArgumentException,
CancelException {
CancelException, WalaException {
PropagationCallGraphBuilder b = makeCGBuilder(makeLoaders(), scripts, builderType, irFactory);
CallGraph CG = b.makeCallGraph(b.getOptions());
// dumpCG(b.getPointerAnalysis(), CG);
return CG;
}
public static JSCFABuilder makeHTMLCGBuilder(URL url) throws IOException {
public static JSCFABuilder makeHTMLCGBuilder(URL url) throws IOException, WalaException {
return makeHTMLCGBuilder(url, CGBuilderType.ZERO_ONE_CFA);
}
public static JSCFABuilder makeHTMLCGBuilder(URL url, CGBuilderType builderType) throws IOException {
public static JSCFABuilder makeHTMLCGBuilder(URL url, CGBuilderType builderType) throws IOException, WalaException {
JavaScriptLoader.addBootstrapFile(WebUtil.preamble);
Set<MappedSourceModule> script = WebUtil.extractScriptFromHTML(url);
JSCFABuilder builder = makeCGBuilder(new WebPageLoaderFactory(translatorFactory, preprocessor), script.toArray(new SourceModule[script.size()]), builderType, AstIRFactory.makeDefaultFactory());
SourceModule[] scripts;
IRFactory irFactory = AstIRFactory.makeDefaultFactory();
JavaScriptLoaderFactory loaders = new WebPageLoaderFactory(translatorFactory, preprocessor);
try {
Set<MappedSourceModule> script = WebUtil.extractScriptFromHTML(url);
scripts = script.toArray(new SourceModule[script.size()]);
} catch (Error e) {
SourceModule dummy = new SourceURLModule(url);
scripts = new SourceModule[]{ dummy };
((CAstAbstractLoader)loaders.getTheLoader()).addMessage(dummy, e.warning);
}
JSCFABuilder builder = makeCGBuilder(loaders, scripts, builderType, irFactory);
builder.setBaseURL(url);
return builder;
}
public static CallGraph makeHTMLCG(URL url) throws IOException, IllegalArgumentException, CancelException {
public static CallGraph makeHTMLCG(URL url) throws IOException, IllegalArgumentException, CancelException, WalaException {
PropagationCallGraphBuilder b = makeHTMLCGBuilder(url);
CallGraph CG = b.makeCallGraph(b.getOptions());
dumpCG(b.getPointerAnalysis(), CG);
@ -143,18 +157,18 @@ public class JSCallGraphBuilderUtil extends com.ibm.wala.cast.js.ipa.callgraph.J
}
public static CallGraph makeHTMLCG(URL url, CGBuilderType builderType) throws IOException, IllegalArgumentException,
CancelException {
CancelException, WalaException {
PropagationCallGraphBuilder b = makeHTMLCGBuilder(url, builderType);
CallGraph CG = b.makeCallGraph(b.getOptions());
return CG;
}
public static JSCFABuilder makeCGBuilder(JavaScriptLoaderFactory loaders, SourceModule[] scripts, CGBuilderType builderType, IRFactory irFactory) throws IOException {
public static JSCFABuilder makeCGBuilder(JavaScriptLoaderFactory loaders, SourceModule[] scripts, CGBuilderType builderType, IRFactory irFactory) throws IOException, WalaException {
AnalysisScope scope = makeScope(scripts, loaders, JavaScriptLoader.JS);
return makeCG(loaders, scope, builderType, irFactory);
}
protected static JSCFABuilder makeCG(JavaScriptLoaderFactory loaders, AnalysisScope scope, CGBuilderType builderType, IRFactory irFactory) throws IOException {
protected static JSCFABuilder makeCG(JavaScriptLoaderFactory loaders, AnalysisScope scope, CGBuilderType builderType, IRFactory irFactory) throws IOException, WalaException {
try {
IClassHierarchy cha = makeHierarchy(scope, loaders);
com.ibm.wala.cast.js.util.Util.checkForFrontEndErrors(cha);

View File

@ -18,6 +18,7 @@ import org.junit.Test;
import com.ibm.wala.cast.js.test.JSCallGraphBuilderUtil.CGBuilderType;
import com.ibm.wala.ipa.callgraph.CallGraph;
import com.ibm.wala.util.CancelException;
import com.ibm.wala.util.WalaException;
public abstract class TestAjaxsltCallGraphShape extends TestJSCallGraphShape {
@ -29,7 +30,7 @@ public abstract class TestAjaxsltCallGraphShape extends TestJSCallGraphShape {
};
@Test public void testAjaxslt() throws IOException, IllegalArgumentException, CancelException {
@Test public void testAjaxslt() throws IOException, IllegalArgumentException, CancelException, WalaException {
URL url = getClass().getClassLoader().getResource("ajaxslt/test/xslt.html");
// don't handle call / apply; it makes things blow up
CallGraph CG = JSCallGraphBuilderUtil.makeHTMLCG(url, CGBuilderType.ZERO_ONE_CFA_NO_CALL_APPLY);
@ -41,7 +42,7 @@ public abstract class TestAjaxsltCallGraphShape extends TestJSCallGraphShape {
};
@Test public void testAjaxpath() throws IOException, IllegalArgumentException, CancelException {
@Test public void testAjaxpath() throws IOException, IllegalArgumentException, CancelException, WalaException {
URL url = getClass().getClassLoader().getResource("ajaxslt/test/xpath.html");
CallGraph CG = JSCallGraphBuilderUtil.makeHTMLCG(url);
verifyGraphAssertions(CG, assertionsForAjaxpath);

View File

@ -18,6 +18,7 @@ import com.ibm.wala.ipa.callgraph.propagation.cfa.ZeroXInstanceKeys;
import com.ibm.wala.ipa.cha.ClassHierarchyException;
import com.ibm.wala.ipa.cha.IClassHierarchy;
import com.ibm.wala.util.CancelException;
import com.ibm.wala.util.WalaException;
public abstract class TestArgumentSensitivity extends TestJSCallGraphShape {
@ -29,7 +30,7 @@ public abstract class TestArgumentSensitivity extends TestJSCallGraphShape {
new Object[] { "tests/args.js/a", new String[] { "tests/args.js/x"} },
new Object[] { "tests/args.js/a", new String[] { "tests/args.js/y", "tests/args.js/z", "!tests/args.js/wrong" } } };
@Test public void testArgs() throws IOException, IllegalArgumentException, CancelException, ClassHierarchyException {
@Test public void testArgs() throws IOException, IllegalArgumentException, CancelException, ClassHierarchyException, WalaException {
JavaScriptLoaderFactory loaders = JSCallGraphBuilderUtil.makeLoaders();
AnalysisScope scope = JSCallGraphBuilderUtil.makeScriptScope("tests", "args.js", loaders);

View File

@ -13,6 +13,7 @@ import com.ibm.wala.cast.js.ipa.callgraph.JSCFABuilder;
import com.ibm.wala.ipa.callgraph.CallGraph;
import com.ibm.wala.ipa.callgraph.ContextSelector;
import com.ibm.wala.util.CancelException;
import com.ibm.wala.util.WalaException;
public abstract class TestForInLoopHack extends TestJSCallGraphShape {
@ -22,14 +23,14 @@ public abstract class TestForInLoopHack extends TestJSCallGraphShape {
JSSourceExtractor.DELETE_UPON_EXIT = false;
}
@Test public void testPage3WithoutHack() throws IOException, IllegalArgumentException, CancelException {
@Test public void testPage3WithoutHack() throws IOException, IllegalArgumentException, CancelException, WalaException {
URL url = getClass().getClassLoader().getResource("pages/page3.html");
JSCFABuilder builder = JSCallGraphBuilderUtil.makeHTMLCGBuilder(url);
CallGraph CG = builder.makeCallGraph(builder.getOptions());
JSCallGraphBuilderUtil.dumpCG(builder.getPointerAnalysis(), CG);
}
@Test public void testPage3WithHack() throws IOException, IllegalArgumentException, CancelException {
@Test public void testPage3WithHack() throws IOException, IllegalArgumentException, CancelException, WalaException {
URL url = getClass().getClassLoader().getResource("pages/page3.html");
JSCFABuilder builder = JSCallGraphBuilderUtil.makeHTMLCGBuilder(url);
addHackedForInLoopSensitivity(builder);
@ -38,7 +39,7 @@ public abstract class TestForInLoopHack extends TestJSCallGraphShape {
}
@Ignore("This test now blows up due to proper handling of the || construct, used in extend(). Should handle this eventually.")
@Test public void testJQueryWithHack() throws IOException, IllegalArgumentException, CancelException {
@Test public void testJQueryWithHack() throws IOException, IllegalArgumentException, CancelException, WalaException {
URL url = getClass().getClassLoader().getResource("pages/jquery_hacked.html");
JSCFABuilder builder = JSCallGraphBuilderUtil.makeHTMLCGBuilder(url);
addHackedForInLoopSensitivity(builder);
@ -47,7 +48,7 @@ public abstract class TestForInLoopHack extends TestJSCallGraphShape {
}
/*
@Test public void testJQueryEx1WithHack() throws IOException, IllegalArgumentException, CancelException {
@Test public void testJQueryEx1WithHack() throws IOException, IllegalArgumentException, CancelException, WalaException {
URL url = getClass().getClassLoader().getResource("pages/jquery/ex1.html");
JSCFABuilder builder = Util.makeHTMLCGBuilder(url);
addHackedForInLoopSensitivity(builder);
@ -73,7 +74,7 @@ public abstract class TestForInLoopHack extends TestJSCallGraphShape {
new String[] { "tests/badforin.js/testForIn2" } }
};
@Test public void testBadForInWithoutHack() throws IOException, IllegalArgumentException, CancelException {
@Test public void testBadForInWithoutHack() throws IOException, IllegalArgumentException, CancelException, WalaException {
JSCFABuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "badforin.js");
CallGraph CG = B.makeCallGraph(B.getOptions());
JSCallGraphBuilderUtil.dumpCG(B.getPointerAnalysis(), CG);
@ -91,7 +92,7 @@ public abstract class TestForInLoopHack extends TestJSCallGraphShape {
new String[] { "!tests/badforin.js/testForIn1" } }
};
@Test public void testBadForInWithHack() throws IOException, IllegalArgumentException, CancelException {
@Test public void testBadForInWithHack() throws IOException, IllegalArgumentException, CancelException, WalaException {
JSCFABuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "badforin.js");
addHackedForInLoopSensitivity(B);
CallGraph CG = B.makeCallGraph(B.getOptions());
@ -117,7 +118,7 @@ public abstract class TestForInLoopHack extends TestJSCallGraphShape {
new String[] { "tests/badforin2.js/testForIn2" } }
};
@Test public void testbadforin2WithoutHack() throws IOException, IllegalArgumentException, CancelException {
@Test public void testbadforin2WithoutHack() throws IOException, IllegalArgumentException, CancelException, WalaException {
JSCFABuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "badforin2.js");
CallGraph CG = B.makeCallGraph(B.getOptions());
JSCallGraphBuilderUtil.dumpCG(B.getPointerAnalysis(), CG);
@ -135,7 +136,7 @@ public abstract class TestForInLoopHack extends TestJSCallGraphShape {
new String[] { "!tests/badforin2.js/testForIn1" } }
};
@Test public void testbadforin2WithHack() throws IOException, IllegalArgumentException, CancelException {
@Test public void testbadforin2WithHack() throws IOException, IllegalArgumentException, CancelException, WalaException {
JSCFABuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "badforin2.js");
addHackedForInLoopSensitivity(B);
CallGraph CG = B.makeCallGraph(B.getOptions());
@ -144,7 +145,7 @@ public abstract class TestForInLoopHack extends TestJSCallGraphShape {
verifyGraphAssertions(CG, assertionsForbadforin2HackPrecision);
}
@Test public void testForInRecursion() throws IOException, IllegalArgumentException, CancelException {
@Test public void testForInRecursion() throws IOException, IllegalArgumentException, CancelException, WalaException {
JSCFABuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "badforin3.js");
addHackedForInLoopSensitivity(B);
CallGraph CG = B.makeCallGraph(B.getOptions());
@ -153,7 +154,7 @@ public abstract class TestForInLoopHack extends TestJSCallGraphShape {
/*
@Test public void testYahooWithoutHack() throws IOException, IllegalArgumentException, CancelException {
@Test public void testYahooWithoutHack() throws IOException, IllegalArgumentException, CancelException, WalaException {
JSCFABuilder B = Util.makeScriptCGBuilder("frameworks", "yahoo.js");
CallGraph CG = B.makeCallGraph(B.getOptions());
Util.dumpCG(B.getPointerAnalysis(), CG);

View File

@ -12,6 +12,7 @@ import com.ibm.wala.cast.js.html.JSSourceExtractor;
import com.ibm.wala.cast.js.ipa.callgraph.JSCFABuilder;
import com.ibm.wala.ipa.callgraph.CallGraph;
import com.ibm.wala.util.CancelException;
import com.ibm.wala.util.WalaException;
public class TestJQueryExamples extends TestJSCallGraphShape {
@ -26,7 +27,7 @@ public class TestJQueryExamples extends TestJSCallGraphShape {
}
@Ignore("This tries to analyze unmodified jquery, which we can't do yet")
@Test public void testEx1() throws IOException, IllegalArgumentException, CancelException {
@Test public void testEx1() throws IOException, IllegalArgumentException, CancelException, WalaException {
URL url = getClass().getClassLoader().getResource("pages/jquery/ex1.html");
JSCFABuilder builder = JSCallGraphBuilderUtil.makeHTMLCGBuilder(url);
CallGraph CG = builder.makeCallGraph(builder.getOptions());

View File

@ -22,13 +22,14 @@ import com.ibm.wala.cast.js.ipa.callgraph.JSCFABuilder;
import com.ibm.wala.ipa.callgraph.CGNode;
import com.ibm.wala.ipa.callgraph.CallGraph;
import com.ibm.wala.util.CancelException;
import com.ibm.wala.util.WalaException;
import com.ibm.wala.util.collections.Pair;
import com.ibm.wala.util.intset.OrdinalSet;
public abstract class TestLexicalModRef {
@Test
public void testSimpleLexical() throws IOException, IllegalArgumentException, CancelException {
public void testSimpleLexical() throws IOException, IllegalArgumentException, CancelException, WalaException {
JSCFABuilder b = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "simple-lexical.js");
CallGraph CG = b.makeCallGraph(b.getOptions());
LexicalModRef lexAccesses = LexicalModRef.make(CG, b.getPointerAnalysis());
@ -50,7 +51,14 @@ public abstract class TestLexicalModRef {
// function "inner3" reads exactly innerName, inner3, and x and z via callees
OrdinalSet<Pair<CGNode, String>> readVars = readResult.get(n);
Assert.assertEquals(4, readVars.size());
Assert.assertEquals("[[Node: <Code body of function Ltests/simple-lexical.js/outer> Context: Everywhere,x], [Node: <Code body of function Ltests/simple-lexical.js/outer> Context: Everywhere,inner3], [Node: <Code body of function Ltests/simple-lexical.js/outer> Context: Everywhere,innerName], [Node: <Code body of function Ltests/simple-lexical.js/outer> Context: Everywhere,z]]", readVars.toString());
for(Pair<CGNode, String> rv : readVars) {
Assert.assertTrue(rv.toString(),
"[Node: <Code body of function Ltests/simple-lexical.js/outer> Context: Everywhere,x]".equals(rv.toString()) ||
"[Node: <Code body of function Ltests/simple-lexical.js/outer> Context: Everywhere,inner3]".equals(rv.toString()) ||
"[Node: <Code body of function Ltests/simple-lexical.js/outer> Context: Everywhere,innerName]".equals(rv.toString()) ||
"[Node: <Code body of function Ltests/simple-lexical.js/outer> Context: Everywhere,z]".equals(rv.toString()));
}
}
}
}

View File

@ -18,6 +18,7 @@ import org.junit.Test;
import com.ibm.wala.ipa.callgraph.CallGraph;
import com.ibm.wala.util.CancelException;
import com.ibm.wala.util.WalaException;
public abstract class TestMediawikiCallGraphShape extends TestJSCallGraphShape {
@ -30,7 +31,7 @@ public abstract class TestMediawikiCallGraphShape extends TestJSCallGraphShape {
};
@Ignore("not terminating; Julian, take a look?")
@Test public void testSwineFlu() throws IOException, IllegalArgumentException, CancelException {
@Test public void testSwineFlu() throws IOException, IllegalArgumentException, CancelException, WalaException {
URL url = new URL("http://en.wikipedia.org/wiki/2009_swine_flu_outbreak");
CallGraph CG = JSCallGraphBuilderUtil.makeHTMLCG(url);
verifyGraphAssertions(CG, assertionsForSwineFlu);

View File

@ -19,19 +19,22 @@ import junit.framework.Assert;
import org.junit.Test;
import com.ibm.wala.cast.ipa.callgraph.CAstCallGraphUtil;
import com.ibm.wala.cast.js.ipa.callgraph.ForInContextSelector;
import com.ibm.wala.cast.js.ipa.callgraph.JSCFABuilder;
import com.ibm.wala.cast.js.ipa.callgraph.JSCallGraphUtil;
import com.ibm.wala.ipa.callgraph.CGNode;
import com.ibm.wala.ipa.callgraph.CallGraph;
import com.ibm.wala.ipa.callgraph.CallGraphBuilderCancelException;
import com.ibm.wala.ipa.callgraph.propagation.InstanceKey;
import com.ibm.wala.ipa.callgraph.propagation.LocalPointerKey;
import com.ibm.wala.ipa.callgraph.propagation.PointerAnalysis;
import com.ibm.wala.ipa.callgraph.propagation.PointerKey;
import com.ibm.wala.ipa.callgraph.propagation.PropagationCallGraphBuilder;
import com.ibm.wala.ipa.callgraph.propagation.SSAPropagationCallGraphBuilder;
import com.ibm.wala.ssa.SSAInstruction;
import com.ibm.wala.util.CancelException;
import com.ibm.wala.util.MonitorUtil.IProgressMonitor;
import com.ibm.wala.util.WalaException;
import com.ibm.wala.util.collections.HashSetFactory;
import com.ibm.wala.util.collections.IVector;
import com.ibm.wala.util.collections.Iterator2Collection;
@ -53,7 +56,7 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
new String[] { "tests/args.js/a" } },
new Object[] { "tests/args.js/a", new String[] { "tests/args.js/x", "tests/args.js/y" } } };
@Test public void testArgs() throws IOException, IllegalArgumentException, CancelException {
@Test public void testArgs() throws IOException, IllegalArgumentException, CancelException, WalaException {
CallGraph CG = JSCallGraphBuilderUtil.makeScriptCG("tests", "args.js");
verifyGraphAssertions(CG, assertionsForArgs);
}
@ -71,7 +74,7 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
new Object[] { "tests/simple.js/weirder", new String[] { "prologue.js/Math_abs" } } };
@Test
public void testSimple() throws IOException, IllegalArgumentException, CancelException {
public void testSimple() throws IOException, IllegalArgumentException, CancelException, WalaException {
CallGraph CG = JSCallGraphBuilderUtil.makeScriptCG("tests", "simple.js");
verifyGraphAssertions(CG, assertionsForSimple);
}
@ -85,7 +88,7 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
new Object[] { "tests/objects.js/objects_are_fun", new String[] { "tests/objects.js/other", "tests/objects.js/whatever" } } };
@Test
public void testObjects() throws IOException, IllegalArgumentException, CancelException {
public void testObjects() throws IOException, IllegalArgumentException, CancelException, WalaException {
CallGraph CG = JSCallGraphBuilderUtil.makeScriptCG("tests", "objects.js");
verifyGraphAssertions(CG, assertionsForObjects);
}
@ -106,7 +109,7 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
};
@Test
public void testInherit() throws IOException, IllegalArgumentException, CancelException {
public void testInherit() throws IOException, IllegalArgumentException, CancelException, WalaException {
CallGraph CG = JSCallGraphBuilderUtil.makeScriptCG("tests", "inherit.js");
verifyGraphAssertions(CG, assertionsForInherit);
}
@ -117,7 +120,7 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
new String[] { "suffix:ctor$1/_fromctor", "suffix:ctor$2/_fromctor", "suffix:ctor$3/_fromctor" } } };
@Test
public void testNewfn() throws IOException, IllegalArgumentException, CancelException {
public void testNewfn() throws IOException, IllegalArgumentException, CancelException, WalaException {
CallGraph CG = JSCallGraphBuilderUtil.makeScriptCG("tests", "newfn.js");
verifyGraphAssertions(CG, assertionsForNewfn);
}
@ -130,7 +133,7 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
"tests/control-flow.js/testWhile", "tests/control-flow.js/testFor", "tests/control-flow.js/testReturn" } } };
@Test
public void testControlflow() throws IOException, IllegalArgumentException, CancelException {
public void testControlflow() throws IOException, IllegalArgumentException, CancelException, WalaException {
CallGraph CG = JSCallGraphBuilderUtil.makeScriptCG("tests", "control-flow.js");
verifyGraphAssertions(CG, assertionsForControlflow);
}
@ -144,7 +147,7 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
"tests/more-control-flow.js/testFor", "tests/more-control-flow.js/testReturn" } } };
@Test
public void testMoreControlflow() throws IOException, IllegalArgumentException, CancelException {
public void testMoreControlflow() throws IOException, IllegalArgumentException, CancelException, WalaException {
CallGraph CG = JSCallGraphBuilderUtil.makeScriptCG("tests", "more-control-flow.js");
verifyGraphAssertions(CG, assertionsForMoreControlflow);
}
@ -154,7 +157,7 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
new Object[] { "tests/forin.js/testForIn", new String[] { "tests/forin.js/testForIn1", "tests/forin.js/testForIn2" } } };
@Test
public void testForin() throws IOException, IllegalArgumentException, CancelException {
public void testForin() throws IOException, IllegalArgumentException, CancelException, WalaException {
JSCFABuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "forin.js");
CallGraph CG = B.makeCallGraph(B.getOptions());
// JSCallGraphUtil.AVOID_DUMP = false;
@ -175,13 +178,13 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
new String[] { "tests/simple-lexical.js/outer/inner", "tests/simple-lexical.js/outer/inner3" } } };
@Test
public void testSimpleLexical() throws IOException, IllegalArgumentException, CancelException {
public void testSimpleLexical() throws IOException, IllegalArgumentException, CancelException, WalaException {
CallGraph CG = JSCallGraphBuilderUtil.makeScriptCG("tests", "simple-lexical.js");
verifyGraphAssertions(CG, assertionsForSimpleLexical);
}
@Test
public void testRecursiveLexical() throws IOException, IllegalArgumentException, CancelException {
public void testRecursiveLexical() throws IOException, IllegalArgumentException, CancelException, WalaException {
// just checking that we have a sufficient bailout to ensure termination
JSCallGraphBuilderUtil.makeScriptCG("tests", "recursive_lexical.js");
}
@ -192,7 +195,7 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
new Object[] { "suffix:lexical_multiple_calls.js", new String[] { "suffix:reachable2" } }};
@Test
public void testLexicalMultiple() throws IOException, IllegalArgumentException, CancelException {
public void testLexicalMultiple() throws IOException, IllegalArgumentException, CancelException, WalaException {
CallGraph CG = JSCallGraphBuilderUtil.makeScriptCG("tests", "lexical_multiple_calls.js");
verifyGraphAssertions(CG, assertionsForLexicalMultiple);
}
@ -210,7 +213,7 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
new String[] { "tests/try.js/targetOne", "tests/try.js/targetTwo", "tests/try.js/three", "tests/try.js/two" } } };
@Test
public void testTry() throws IOException, IllegalArgumentException, CancelException {
public void testTry() throws IOException, IllegalArgumentException, CancelException, WalaException {
CallGraph CG = JSCallGraphBuilderUtil.makeScriptCG("tests", "try.js");
verifyGraphAssertions(CG, assertionsForTry);
}
@ -220,7 +223,7 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
new Object[] { "tests/string-op.js", new String[] { "tests/string-op.js/getOp", "tests/string-op.js/plusNum" } } };
@Test
public void testStringOp() throws IOException, IllegalArgumentException, CancelException {
public void testStringOp() throws IOException, IllegalArgumentException, CancelException, WalaException {
PropagationCallGraphBuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "string-op.js");
B.getOptions().setTraceStringConstants(true);
CallGraph CG = B.makeCallGraph(B.getOptions());
@ -235,7 +238,7 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
"tests/upward.js/tester2" } } };
@Test
public void testUpward() throws IOException, IllegalArgumentException, CancelException {
public void testUpward() throws IOException, IllegalArgumentException, CancelException, WalaException {
CallGraph CG = JSCallGraphBuilderUtil.makeScriptCG("tests", "upward.js");
verifyGraphAssertions(CG, assertionsForUpward);
}
@ -245,7 +248,7 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
new Object[] { "tests/string-prims.js", new String[] { "prologue.js/String_prototype_split", "prologue.js/String_prototype_toUpperCase" } } };
@Test
public void testStringPrims() throws IOException, IllegalArgumentException, CancelException {
public void testStringPrims() throws IOException, IllegalArgumentException, CancelException, WalaException {
PropagationCallGraphBuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "string-prims.js");
B.getOptions().setTraceStringConstants(true);
CallGraph CG = B.makeCallGraph(B.getOptions());
@ -258,7 +261,7 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
new Object[] { "tests/nested.js", new String[] { "tests/nested.js/f", "tests/nested.js/f/ff", "tests/nested.js/f/ff/fff" } } };
@Test
public void testNested() throws IOException, IllegalArgumentException, CancelException {
public void testNested() throws IOException, IllegalArgumentException, CancelException, WalaException {
PropagationCallGraphBuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "nested.js");
CallGraph CG = B.makeCallGraph(B.getOptions());
verifyGraphAssertions(CG, assertionsForNested);
@ -268,7 +271,7 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
new String[] { "tests/instanceof.js" } } };
@Test
public void testInstanceof() throws IOException, IllegalArgumentException, CancelException {
public void testInstanceof() throws IOException, IllegalArgumentException, CancelException, WalaException {
PropagationCallGraphBuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "instanceof.js");
CallGraph CG = B.makeCallGraph(B.getOptions());
verifyGraphAssertions(CG, assertionsForInstanceof);
@ -286,19 +289,19 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
*/
@Test
public void testCrash1() throws IOException, IllegalArgumentException, CancelException {
public void testCrash1() throws IOException, IllegalArgumentException, CancelException, WalaException {
CallGraph CG = JSCallGraphBuilderUtil.makeScriptCG("tests", "crash1.js");
verifyGraphAssertions(CG, null);
}
@Test
public void testCrash2() throws IOException, IllegalArgumentException, CancelException {
public void testCrash2() throws IOException, IllegalArgumentException, CancelException, WalaException {
CallGraph CG = JSCallGraphBuilderUtil.makeScriptCG("tests", "crash2.js");
verifyGraphAssertions(CG, null);
}
@Test
public void testLexicalCtor() throws IOException, IllegalArgumentException, CancelException {
public void testLexicalCtor() throws IOException, IllegalArgumentException, CancelException, WalaException {
CallGraph CG = JSCallGraphBuilderUtil.makeScriptCG("tests", "lexical-ctor.js");
verifyGraphAssertions(CG, null);
}
@ -308,7 +311,7 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
new Object[] { "tests/multivar.js", new String[] { "tests/multivar.js/a", "tests/multivar.js/bf", "tests/multivar.js/c" } } };
@Test
public void testMultivar() throws IOException, IllegalArgumentException, CancelException {
public void testMultivar() throws IOException, IllegalArgumentException, CancelException, WalaException {
CallGraph CG = JSCallGraphBuilderUtil.makeScriptCG("tests", "multivar.js");
verifyGraphAssertions(CG, assertionsForMultivar);
}
@ -319,7 +322,7 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
new Object[] { "suffix:test2", new String[] { "suffix:foo_of_B" } } };
@Test
public void testProtoypeContamination() throws IOException, IllegalArgumentException, CancelException {
public void testProtoypeContamination() throws IOException, IllegalArgumentException, CancelException, WalaException {
CallGraph CG = JSCallGraphBuilderUtil.makeScriptCG("tests", "prototype_contamination_bug.js");
verifyGraphAssertions(CG, assertionsForPrototypeContamination);
verifyNoEdges(CG, "suffix:test1", "suffix:foo_of_B");
@ -327,20 +330,20 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
}
@Test
public void testStackOverflowOnSsaConversionBug() throws IOException, IllegalArgumentException, CancelException {
public void testStackOverflowOnSsaConversionBug() throws IOException, IllegalArgumentException, CancelException, WalaException {
JSCallGraphBuilderUtil.makeScriptCG("tests", "stack_overflow_on_ssa_conversion.js");
// all we need is for it to finish building CG successfully.
}
@Test
public void testExtJSSwitch() throws IOException, IllegalArgumentException, CancelException {
public void testExtJSSwitch() throws IOException, IllegalArgumentException, CancelException, WalaException {
JSCallGraphBuilderUtil.makeScriptCG("tests", "extjs_switch.js");
// all we need is for it to finish building CG successfully.
}
@Test
public void testFunctionDotCall() throws IOException, IllegalArgumentException, CancelException {
public void testFunctionDotCall() throws IOException, IllegalArgumentException, CancelException, WalaException {
CallGraph cg = JSCallGraphBuilderUtil.makeScriptCG("tests", "function_call.js");
for (CGNode n : cg) {
if (n.getMethod().getName().toString().equals("call4")) {
@ -362,7 +365,7 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
@Test
public void testFunctionDotApply() throws IOException, IllegalArgumentException, CancelException {
public void testFunctionDotApply() throws IOException, IllegalArgumentException, CancelException, WalaException {
CallGraph CG = JSCallGraphBuilderUtil.makeScriptCG("tests", "function_apply.js");
verifyGraphAssertions(CG, assertionsForFunctionApply);
}
@ -372,7 +375,7 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
new Object[] { "suffix:function_apply2.js", new String[] { "suffix:theThree" } } };
@Test
public void testFunctionDotApply2() throws IOException, IllegalArgumentException, CancelException {
public void testFunctionDotApply2() throws IOException, IllegalArgumentException, CancelException, WalaException {
CallGraph CG = JSCallGraphBuilderUtil.makeScriptCG("tests", "function_apply2.js");
verifyGraphAssertions(CG, assertionsForFunctionApply2);
}
@ -382,7 +385,7 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
new Object[] { "suffix:wrap1.js", new String[] { "suffix:i_am_reachable" } } };
@Test
public void testWrap1() throws IllegalArgumentException, IOException, CancelException {
public void testWrap1() throws IllegalArgumentException, IOException, CancelException, WalaException {
CallGraph CG = JSCallGraphBuilderUtil.makeScriptCG("tests", "wrap1.js");
verifyGraphAssertions(CG, assertionsForWrap1);
}
@ -392,7 +395,7 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
new Object[] { "suffix:wrap2.js", new String[] { "suffix:i_am_reachable" } } };
@Test
public void testWrap2() throws IllegalArgumentException, IOException, CancelException {
public void testWrap2() throws IllegalArgumentException, IOException, CancelException, WalaException {
CallGraph CG = JSCallGraphBuilderUtil.makeScriptCG("tests", "wrap2.js");
verifyGraphAssertions(CG, assertionsForWrap2);
}
@ -402,7 +405,7 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
new Object[] { "suffix:wrap3.js", new String[] { "suffix:i_am_reachable" } } };
@Test
public void testWrap3() throws IllegalArgumentException, IOException, CancelException {
public void testWrap3() throws IllegalArgumentException, IOException, CancelException, WalaException {
CallGraph CG = JSCallGraphBuilderUtil.makeScriptCG("tests", "wrap3.js");
verifyGraphAssertions(CG, assertionsForWrap3);
}
@ -412,7 +415,7 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
new Object[] { "suffix:call.js", new String[] { "suffix:f3" } } };
@Test
public void testComplexCall() throws IOException, IllegalArgumentException, CancelException {
public void testComplexCall() throws IOException, IllegalArgumentException, CancelException, WalaException {
CallGraph CG = JSCallGraphBuilderUtil.makeScriptCG("tests", "complex_call.js");
for(CGNode nd : CG)
System.out.println(nd);
@ -425,7 +428,7 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
new Object[] { "suffix:global_object.js", new String[] { "suffix:biz" } } };
@Test
public void testGlobalObjPassing() throws IOException, IllegalArgumentException, CancelException {
public void testGlobalObjPassing() throws IOException, IllegalArgumentException, CancelException, WalaException {
CallGraph CG = JSCallGraphBuilderUtil.makeScriptCG("tests", "global_object.js");
verifyGraphAssertions(CG, assertionsForGlobalObj);
}
@ -435,7 +438,7 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
new Object[] { "suffix:global_object2.js", new String[] { "suffix:foo" } } };
@Test
public void testGlobalObj2() throws IOException, IllegalArgumentException, CancelException {
public void testGlobalObj2() throws IOException, IllegalArgumentException, CancelException, WalaException {
CallGraph CG = JSCallGraphBuilderUtil.makeScriptCG("tests", "global_object2.js");
verifyGraphAssertions(CG, assertionsForGlobalObj2);
}
@ -447,7 +450,7 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
new Object[] { "suffix:return_this.js", new String[] { "suffix:bar" } } };
@Test
public void testReturnThis() throws IOException, IllegalArgumentException, CancelException {
public void testReturnThis() throws IOException, IllegalArgumentException, CancelException, WalaException {
PropagationCallGraphBuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "return_this.js");
CallGraph CG = B.makeCallGraph(B.getOptions());
// JSCallGraphUtil.AVOID_DUMP = false;
@ -468,7 +471,7 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
// and test2 does not call bar1
@Test
public void testReturnThis2() throws IOException, IllegalArgumentException, CancelException {
public void testReturnThis2() throws IOException, IllegalArgumentException, CancelException, WalaException {
CallGraph CG = JSCallGraphBuilderUtil.makeScriptCG("tests", "return_this2.js");
verifyGraphAssertions(CG, assertionsForReturnThis2);
}
@ -480,7 +483,7 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
};
@Test
public void testArguments() throws IOException, IllegalArgumentException, CancelException {
public void testArguments() throws IOException, IllegalArgumentException, CancelException, WalaException {
CallGraph CG = JSCallGraphBuilderUtil.makeScriptCG("tests", "arguments.js");
verifyGraphAssertions(CG, assertionsForArguments);
}
@ -490,7 +493,7 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
new Object[] { "suffix:Function_is_a_function.js", new String[] { "suffix:Function_prototype_call" } } };
@Test
public void testFunctionIsAFunction() throws IOException, IllegalArgumentException, CancelException {
public void testFunctionIsAFunction() throws IOException, IllegalArgumentException, CancelException, WalaException {
CallGraph CG = JSCallGraphBuilderUtil.makeScriptCG("tests", "Function_is_a_function.js");
verifyGraphAssertions(CG, assertionsForFunctionIsAFunction);
}
@ -502,13 +505,13 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
};
@Test
public void testLexicalBroken() throws IOException, IllegalArgumentException, CancelException {
public void testLexicalBroken() throws IOException, IllegalArgumentException, CancelException, WalaException {
CallGraph CG = JSCallGraphBuilderUtil.makeScriptCG("tests", "lexical_broken.js");
verifyGraphAssertions(CG, assertionsForLexicalBroken);
}
@Test
public void testDeadPhi() throws IllegalArgumentException, IOException, CancelException {
public void testDeadPhi() throws IllegalArgumentException, IOException, CancelException, WalaException {
JSCallGraphBuilderUtil.makeScriptCG("tests", "dead_phi.js");
}
@ -518,7 +521,7 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
};
@Test
public void testScopingOverwriteFunction() throws IllegalArgumentException, IOException, CancelException {
public void testScopingOverwriteFunction() throws IllegalArgumentException, IOException, CancelException, WalaException {
CallGraph CG = JSCallGraphBuilderUtil.makeScriptCG("tests", "scoping_test.js");
verifyGraphAssertions(CG, assertionsForScopingOverwriteFunction);
}
@ -529,7 +532,7 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
};
@Test
public void testNestedAssignToParam() throws IllegalArgumentException, IOException, CancelException {
public void testNestedAssignToParam() throws IllegalArgumentException, IOException, CancelException, WalaException {
CallGraph CG = JSCallGraphBuilderUtil.makeScriptCG("tests", "nested_assign_to_param.js");
verifyGraphAssertions(CG, assertionsForNestedParamAssign);
}
@ -542,7 +545,7 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
};
@Test
public void testDispatch() throws IOException, IllegalArgumentException, CancelException {
public void testDispatch() throws IOException, IllegalArgumentException, CancelException, WalaException {
PropagationCallGraphBuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "dispatch.js");
CallGraph CG = B.makeCallGraph(B.getOptions());
// JSCallGraphUtil.AVOID_DUMP = false;
@ -557,7 +560,7 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
@Test
public void testDispatchSameTarget() throws IOException, IllegalArgumentException, CancelException {
public void testDispatchSameTarget() throws IOException, IllegalArgumentException, CancelException, WalaException {
PropagationCallGraphBuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "dispatch_same_target.js");
CallGraph CG = B.makeCallGraph(B.getOptions());
// JSCallGraphUtil.AVOID_DUMP = false;
@ -574,7 +577,7 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
};
@Test
public void testForInPrototype() throws IllegalArgumentException, IOException, CancelException {
public void testForInPrototype() throws IllegalArgumentException, IOException, CancelException, WalaException {
CallGraph cg = JSCallGraphBuilderUtil.makeScriptCG("tests", "for_in_prototype.js");
verifyGraphAssertions(cg, assertionsForForInPrototype);
}
@ -588,7 +591,7 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
};
@Test
public void testArrayIndexConv() throws IllegalArgumentException, IOException, CancelException {
public void testArrayIndexConv() throws IllegalArgumentException, IOException, CancelException, WalaException {
PropagationCallGraphBuilder b = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "array_index_conv.js");
CallGraph cg = b.makeCallGraph(b.getOptions());
verifyGraphAssertions(cg, assertionsForArrayIndexConv);
@ -603,7 +606,7 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
};
@Test
public void testArrayIndexConv2() throws IllegalArgumentException, IOException, CancelException {
public void testArrayIndexConv2() throws IllegalArgumentException, IOException, CancelException, WalaException {
PropagationCallGraphBuilder b = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "array_index_conv2.js");
b.setContextSelector(new ForInContextSelector(b.getContextSelector()));
CallGraph cg = b.makeCallGraph(b.getOptions());
@ -618,7 +621,7 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
};
@Test
public void testDateAsProperty() throws IllegalArgumentException, IOException, CancelException {
public void testDateAsProperty() throws IllegalArgumentException, IOException, CancelException, WalaException {
PropagationCallGraphBuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "date-property.js");
CallGraph CG = B.makeCallGraph(B.getOptions());
//JSCallGraphUtil.AVOID_DUMP = false;
@ -626,6 +629,40 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
verifyGraphAssertions(CG, assertionsForDateProperty);
}
private static final Object[][] assertionsForDeadCode = new Object[][] {
new Object[] { ROOT, new String[] { "tests/dead.js" } },
new Object[] { "tests/dead.js", new String[] { "suffix:twoReturns" } }
};
@Test
public void testDeadCode() throws IllegalArgumentException, IOException, CancelException, WalaException {
PropagationCallGraphBuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "dead.js");
CallGraph CG = B.makeCallGraph(B.getOptions());
//JSCallGraphUtil.AVOID_DUMP = false;
//JSCallGraphUtil.dumpCG(B.getPointerAnalysis(), CG);
verifyGraphAssertions(CG, assertionsForDeadCode);
}
@Test(expected = CallGraphBuilderCancelException.class)
public void testManyStrings() throws IllegalArgumentException, IOException, CancelException, WalaException {
SSAPropagationCallGraphBuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "many-strings.js");
B.getOptions().setTraceStringConstants(true);
final long startTime = System.currentTimeMillis();
CallGraph CG = B.makeCallGraph(B.getOptions(), new IProgressMonitor() {
public void beginTask(String task, int totalWork) {
}
public boolean isCanceled() {
return System.currentTimeMillis() > (startTime + 10000L);
}
public void done() {
}
public void worked(int units) {
}
});
JSCallGraphUtil.AVOID_DUMP = false;
JSCallGraphUtil.dumpCG(B.getPointerAnalysis(), CG);
}
protected IVector<Set<Pair<CGNode, Integer>>> computeIkIdToVns(PointerAnalysis pa) {
// Created by reversing the points to mapping for local pointer keys.

View File

@ -22,6 +22,7 @@ import com.ibm.wala.cast.js.html.WebUtil;
import com.ibm.wala.cast.js.ipa.callgraph.JSCFABuilder;
import com.ibm.wala.ipa.callgraph.CallGraph;
import com.ibm.wala.util.CancelException;
import com.ibm.wala.util.WalaException;
public abstract class TestSimplePageCallGraphShape extends TestJSCallGraphShape {
@ -52,7 +53,7 @@ public abstract class TestSimplePageCallGraphShape extends TestJSCallGraphShape
}
};
@Test public void testPage1() throws IOException, IllegalArgumentException, CancelException {
@Test public void testPage1() throws IOException, IllegalArgumentException, CancelException, WalaException {
URL url = getClass().getClassLoader().getResource("pages/page1.html");
CallGraph CG = JSCallGraphBuilderUtil.makeHTMLCG(url);
verifyGraphAssertions(CG, assertionsForPage1);
@ -63,7 +64,7 @@ public abstract class TestSimplePageCallGraphShape extends TestJSCallGraphShape
new Object[] { "page2.html", new String[] { "page2.html/__WINDOW_MAIN__" } }
};
@Test public void testPage2() throws IOException, IllegalArgumentException, CancelException {
@Test public void testPage2() throws IOException, IllegalArgumentException, CancelException, WalaException {
URL url = getClass().getClassLoader().getResource("pages/page2.html");
CallGraph CG = JSCallGraphBuilderUtil.makeHTMLCG(url);
verifyGraphAssertions(CG, assertionsForPage2);
@ -80,7 +81,7 @@ public abstract class TestSimplePageCallGraphShape extends TestJSCallGraphShape
}
};
@Test public void testCrawlPage11() throws IOException, IllegalArgumentException, CancelException {
@Test public void testCrawlPage11() throws IOException, IllegalArgumentException, CancelException, WalaException {
URL url = getClass().getClassLoader().getResource("pages/crawl/page11.html");
CallGraph CG = JSCallGraphBuilderUtil.makeHTMLCG(url);
verifyGraphAssertions(CG, assertionsForPage11);
@ -97,7 +98,7 @@ public abstract class TestSimplePageCallGraphShape extends TestJSCallGraphShape
}
};
@Test public void testCrawlPage11b() throws IOException, IllegalArgumentException, CancelException {
@Test public void testCrawlPage11b() throws IOException, IllegalArgumentException, CancelException, WalaException {
URL url = getClass().getClassLoader().getResource("pages/crawl/page11b.html");
CallGraph CG = JSCallGraphBuilderUtil.makeHTMLCG(url);
verifyGraphAssertions(CG, assertionsForPage11b);
@ -129,7 +130,7 @@ public abstract class TestSimplePageCallGraphShape extends TestJSCallGraphShape
},
};
@Test public void testCrawlPage12() throws IOException, IllegalArgumentException, CancelException {
@Test public void testCrawlPage12() throws IOException, IllegalArgumentException, CancelException, WalaException {
URL url = getClass().getClassLoader().getResource("pages/crawl/page12.html");
CallGraph CG = JSCallGraphBuilderUtil.makeHTMLCG(url);
verifyGraphAssertions(CG, assertionsForPage12);
@ -162,7 +163,7 @@ public abstract class TestSimplePageCallGraphShape extends TestJSCallGraphShape
}
};
@Test public void testCrawlPage13() throws IOException, IllegalArgumentException, CancelException {
@Test public void testCrawlPage13() throws IOException, IllegalArgumentException, CancelException, WalaException {
URL url = getClass().getClassLoader().getResource("pages/crawl/page13.html");
CallGraph CG = JSCallGraphBuilderUtil.makeHTMLCG(url);
verifyGraphAssertions(CG, assertionsForPage13);
@ -180,7 +181,7 @@ public abstract class TestSimplePageCallGraphShape extends TestJSCallGraphShape
}
};
@Test public void testCrawlPage15() throws IOException, IllegalArgumentException, CancelException {
@Test public void testCrawlPage15() throws IOException, IllegalArgumentException, CancelException, WalaException {
URL url = getClass().getClassLoader().getResource("pages/crawl/page15.html");
CallGraph CG = JSCallGraphBuilderUtil.makeHTMLCG(url);
verifyGraphAssertions(CG, assertionsForPage15);
@ -198,7 +199,7 @@ public abstract class TestSimplePageCallGraphShape extends TestJSCallGraphShape
}
};
@Test public void testCrawlPage16() throws IOException, IllegalArgumentException, CancelException {
@Test public void testCrawlPage16() throws IOException, IllegalArgumentException, CancelException, WalaException {
URL url = getClass().getClassLoader().getResource("pages/crawl/page16.html");
CallGraph CG = JSCallGraphBuilderUtil.makeHTMLCG(url);
verifyGraphAssertions(CG, assertionsForPage16);
@ -221,7 +222,7 @@ public abstract class TestSimplePageCallGraphShape extends TestJSCallGraphShape
}
};
@Test public void testCrawlPage17() throws IOException, IllegalArgumentException, CancelException {
@Test public void testCrawlPage17() throws IOException, IllegalArgumentException, CancelException, WalaException {
URL url = getClass().getClassLoader().getResource("pages/crawl/page17.html");
CallGraph CG = JSCallGraphBuilderUtil.makeHTMLCG(url);
verifyGraphAssertions(CG, assertionsForPage17);
@ -234,19 +235,19 @@ public abstract class TestSimplePageCallGraphShape extends TestJSCallGraphShape
new Object[] { "apollo-example.html/__WINDOW_MAIN__/signon", new String[] { "preamble.js/DOMWindow/window_open" } }
};
@Test public void testApolloExample() throws IOException, IllegalArgumentException, CancelException {
@Test public void testApolloExample() throws IOException, IllegalArgumentException, CancelException, WalaException {
URL url = getClass().getClassLoader().getResource("pages/apollo-example.html");
CallGraph CG = JSCallGraphBuilderUtil.makeHTMLCG(url);
verifyGraphAssertions(CG, assertionsForApolloExample);
}
@Test public void testNojs() throws IOException, IllegalArgumentException, CancelException {
@Test public void testNojs() throws IOException, IllegalArgumentException, CancelException, WalaException {
URL url = getClass().getClassLoader().getResource("pages/nojs.html");
// all we need is for it to finish building CG successfully.
JSCallGraphBuilderUtil.makeHTMLCG(url);
}
@Test public void testPage4() throws IOException, IllegalArgumentException, CancelException {
@Test public void testPage4() throws IOException, IllegalArgumentException, CancelException, WalaException {
URL url = getClass().getClassLoader().getResource("pages/page4.html");
JSCallGraphBuilderUtil.makeHTMLCG(url);
}
@ -261,7 +262,7 @@ public abstract class TestSimplePageCallGraphShape extends TestJSCallGraphShape
new Object[]{ "suffix:forall_base", "pages/collection.js", 4, 4 }
};
@Test public void testList() throws IOException, IllegalArgumentException, CancelException {
@Test public void testList() throws IOException, IllegalArgumentException, CancelException, WalaException {
URL url = getClass().getClassLoader().getResource("pages/list.html");
JSCFABuilder builder = JSCallGraphBuilderUtil.makeHTMLCGBuilder(url);
CallGraph CG = builder.makeCallGraph(builder.getOptions());
@ -270,7 +271,7 @@ public abstract class TestSimplePageCallGraphShape extends TestJSCallGraphShape
verifySourceAssertions(CG, sourceAssertionsForList);
}
@Test public void testIframeTest2() throws IOException, IllegalArgumentException, CancelException {
@Test public void testIframeTest2() throws IOException, IllegalArgumentException, CancelException, WalaException {
URL url = getClass().getClassLoader().getResource("pages/iframeTest2.html");
JSCallGraphBuilderUtil.makeHTMLCG(url);
}
@ -284,7 +285,7 @@ public abstract class TestSimplePageCallGraphShape extends TestJSCallGraphShape
};
@Test public void testWindowx() throws IOException, IllegalArgumentException, CancelException {
@Test public void testWindowx() throws IOException, IllegalArgumentException, CancelException, WalaException {
URL url = getClass().getClassLoader().getResource("pages/windowx.html");
JSCFABuilder builder = JSCallGraphBuilderUtil.makeHTMLCGBuilder(url);
CallGraph CG = builder.makeCallGraph(builder.getOptions());
@ -293,14 +294,14 @@ public abstract class TestSimplePageCallGraphShape extends TestJSCallGraphShape
}
/*
@Test public void testJQuery() throws IOException, IllegalArgumentException, CancelException {
@Test public void testJQuery() throws IOException, IllegalArgumentException, CancelException, WalaException {
URL url = getClass().getClassLoader().getResource("pages/jquery.html");
CallGraph CG = Util.makeHTMLCG(url);
}
*/
/*
@Test public void testDojoTest() throws IllegalArgumentException, IOException, CancelException {
@Test public void testDojoTest() throws IllegalArgumentException, IOException, CancelException, WalaException {
URL url = getClass().getClassLoader().getResource("pages/dojo/test.html");
CallGraph CG = Util.makeHTMLCG(url);
verifyGraphAssertions(CG, null);

View File

@ -17,20 +17,21 @@ import junit.framework.Assert;
import org.junit.Test;
import com.ibm.wala.cast.ir.translator.TranslatorToCAst.Error;
import com.ibm.wala.cast.js.html.MappedSourceModule;
import com.ibm.wala.cast.js.html.WebUtil;
import com.ibm.wala.core.tests.util.WalaTestCase;
public class TestWebUtil extends WalaTestCase {
@Test public void testAjaxslt() {
@Test public void testAjaxslt() throws Error {
URL url = getClass().getClassLoader().getResource("ajaxslt/test/xslt.html");
Assert.assertTrue(url != null);
Set<MappedSourceModule> mod = WebUtil.extractScriptFromHTML( url );
Assert.assertTrue(mod != null);
}
@Test public void testAjaxpath() {
@Test public void testAjaxpath() throws Error {
URL url = getClass().getClassLoader().getResource("ajaxslt/test/xpath.html");
Assert.assertTrue(url != null);
Set<MappedSourceModule> mod = WebUtil.extractScriptFromHTML( url );

View File

@ -2,6 +2,8 @@
<projectDescription>
<name>com.ibm.wala.cast.js</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>

View File

@ -22,6 +22,9 @@ NamedNodeList = function NamedNodeList() {
var maxLength = 10;
var local = new Array(10);
var counter = -1;
local[0] = new DOMElement();
this[0] = local[0];
var checkAndIncrease = function checkAndIncrease() {
if(counter >= maxLength - 1) {
@ -37,6 +40,11 @@ NamedNodeList = function NamedNodeList() {
this.get = function _get(index) {
return local[ index ];
}
this.item = function _item(index) {
return new DOMElement();
//return local[ index ];
}
this.add = function add(elem) {
checkAndIncrease();
@ -89,6 +97,7 @@ NamedNodeList = function NamedNodeList() {
}
DOMNode = function DOMNode() { // An impostor for the Node class
this.attributes = new NamedNodeList();
this.childNodes = new NamedNodeList();
this.insertBefore = function Node_prototype_insertBefore(newChild, refChild) {
this.childNodes.insertBefore(newChild, refChild);
@ -110,6 +119,10 @@ DOMNode = function DOMNode() { // An impostor for the Node class
this.ownerDocument = document;
this.ownerWindow = window;
this.ownerWindow.XMLHttpRequest = XMLHttpRequest;
//these fields exist so we need to at least stub them out for pointer analysis
this.innerText = new String();
this.innerHTML = new String();
this.collect = function collect(predicate, result) {
if (predicate(this)) {
@ -117,6 +130,9 @@ DOMNode = function DOMNode() { // An impostor for the Node class
}
this.childNodes.collect(predicate, result);
}
this.selectNodes = function(a) {
}
};
DOMNode.prototype.addEventListener = function Node_prototype_addEventListener(name, fn) { fn(); };
@ -147,12 +163,17 @@ DOMDocument = function DOMDocument() {
this.getElementById = function Document_prototype_getElementById(id) {
var result = new Array();
this.collect(function check_id(x) { return x.id == id; }, result);
result[0] = new DOMHTMLGenericElement("model");
//this.collect(function check_id(x) { return x.id == id; }, result);
return result[0];
};
this.getElementsByTagName = function Document_prototype_getElementsByTagName(name) {
// TODO: implement
// TODO: change this to use the tag name and not the ID
var result = new Array();
result[0] = new DOMHTMLGenericElement("model");
//this.collect(function check_id(x) { return x.id == id; }, result);
return result;
};
this.createTextNode = function Document_prototype_createTextNode(txt) {
@ -163,6 +184,10 @@ DOMDocument = function DOMDocument() {
this.write = function Document_prototype_write (stuff) {
};
this.writeln = function Document_prototype_write (stuff) {
};
};
DOMDocument.prototype.createDocumentFragment = function Document_prototype_createDocumentFragment() {
// TODO: model me
@ -193,17 +218,22 @@ DOMHTMLDocument = function DOMHTMLDocument() {
this.forms = new Array();
}
Location = function Location(){
this.port = new String();
this.port.value = new String();
this.host = new String();
this.hostname = new String();
this.href = new String();
this.search = new String();
this.protocol = new String();
this.protocol.value = new String();
this.pathname = new String();
this.toString = function Location_to_string(){
return new String();
}
this.replace = function Location_replace(name) {
}
this.assign = function Location_assign(a) {}
}
Image = function Image() {
@ -270,9 +300,53 @@ document = new DOMHTMLDocument();
// Creating the root window object
window = new DOMWindow();
document.body = new Object();
document.location = location;
window.location = location;
document.domain = new Object();
document.title = new String();
function Referrer() {
this.toString = function () { return new String();}
}
document.referrer = new Referrer();
document.evaluate = function evaluate(a, b, c, d, e) {
}
document.execCommand = function execCommand(a,b,c) {}
function Cookie() {
this.toString = function() { return new String(); }
}
document.cookie = new Cookie();
document.createExpression = function createExpression(a,b) {return new String()}
window.parseFloat = parseFloat;
window.parseInt = parseInt;
function ExecScript(code) {
}
window.execScript = ExecScript;
window.eval = eval;
function prompt(a, b) {
return new String();
}
window.prompt = prompt;
window.escape = escape;
window.encodeURI = encodeURI;
window.encodeURIComponent = encodeURIComponent;
window.unescape = unescape;
window.decodeURI = decodeURI;
window.decodeURIComponent = decodeURIComponent;
window.navigate = function navigate(a) {}
window.document = document;
document.defaultView = window;
window.XMLHttpRequest = XMLHttpRequest;
@ -283,11 +357,20 @@ clearInterval = window.clearInterval;
var dojo = new DOJOObj();
function ElementStyle() {
this.background = new String();
}
DOMElement = function DOMElement() { // An impostor for the Element class
// inherits from Node
this.DOMNode = DOMNode;
this.DOMNode();
delete this.DOMNode;
this.style = new ElementStyle();
this.outerHTML = new String();
this.src = new String();
// The get/set/remove attribute methods cannot be run using 'onclick','onmouseover', 'on...' kind of arguments for name.
// since that would be used as a workaround for eval
@ -303,10 +386,14 @@ DOMElement = function DOMElement() { // An impostor for the Element class
this.removeAttribute = function Element_prototype_removeAttribute(name) {
delete this[name];
};
this.insertAdjacentHTML = function insertAdjacentHTML(a, b) {
};
this.getElementsByTagName = function Element_prototype_getElementsByTagName(tagName) {
var result = new Array();
this.collect(function check_tag(x) { return x.name == tagName; }, result);
result[0] = new DOMHTMLGenericElement("model");
//this.collect(function check_tag(x) { return x.name == tagName; }, result);
return result;
};
@ -359,6 +446,34 @@ DOMHTMLElement = function DOMHTMLElement() { // An impostor for the HTMLElement
this.forms = new Array();
this.formCount = 0;
// Set Javascript properties
this.getAttribute = function getAttribute(name) {
if(name == "id") return this.id;
else if(name == "title") return this.title;
else if(name == "lang") return this.lang;
else if(name == "dir") return this.dir;
else if(name == "class") return this.className;
else return this.attributes.get(name);
}
this.setAttribute = function setAttribute(name, value) {
if(name == "id") this.id = value;
else if(name == "title") this.title = value;
else if(name == "lang") this.lang = value;
else if(name == "dir") this.dir = value;
else if(name == "class") this.className = value;
else return this.attributes.set(name, value);
}
this.removeAttribute = function removeAttribute(name) {
if(name == "id") this.id = null;
else if(name == "title") this.title = null;
else if(name == "lang") this.lang = null;
else if(name == "dir") this.dir = null;
else if(name == "class") this.className = null;
else return this.attributes.remove(name);
}
}
// Just a hack until all HTML elements have corresponding constructors
@ -380,6 +495,7 @@ DOMHTMLGenericElement = function DOMHTMLGenericElement(tagName) {
this.documentWindow = window;
this.getContext = function() { return new CanvasRenderingContext2D(); };
this.getAttribute = function() {return new String();}
};
CanvasRenderingContext2D = function CanvasRenderingContext2D() {};
@ -423,6 +539,37 @@ DOMHTMLFormElement = function DOMHTMLFormElement() {
this.enctype = "application/x-www-form-urlencoded";
this.method = "get";
this.target = null;
// Set Javascript properties
this.getAttribute = function getAttribute(name) {
if(name == "name") return this.name;
else if(name == "accept-charset") return this.acceptCharset;
else if(name == "action") return this.action;
else if(name == "enctype") return this.enctype;
else if(name == "method") return this.method;
else if(name == "target") return this.target;
else return this.prototype.getAttribute(name);
}
this.setAttribute = function setAttribute(name, value) {
if(name == "name") this.name = value;
else if(name == "accept-charset") this.acceptCharset = value;
else if(name == "action") this.action = value;
else if(name == "enctype") this.enctype = value;
else if(name == "method") this.method = value;
else if(name == "target") this.target = value;
else return this.prototype.setAttribute(name, value);
}
this.removeAttribute = function removeAttribute(name) {
if(name == "name") this.name = null;
else if(name == "accept-charset") this.acceptCharset = null;
else if(name == "action") this.action = null;
else if(name == "enctype") this.enctype = null;
else if(name == "method") this.method = null;
else if(name == "target") this.target = null;
else return this.prototype.removeAttribute(name);
}
}
DOMHTMLTableElement = function DOMHTMLTableElement () {
@ -437,12 +584,18 @@ DOMHTMLTableElement = function DOMHTMLTableElement () {
XMLHttpRequest = function XMLHttpRequest() {
this.responseText = new String();
this.responseXML = new DOMNode();
this.UNSENT = 0;
this.OPENED = 1;
this.HEADERS_RECEIVED = 2;
this.LOADING = 3;
this.DONE = 4;
this.onreadystatechange = function xhr_onreadystatechange() {
}
this.orsc_handler = function xhr_orsc_handler() {
this.onreadystatechange();
}
@ -467,11 +620,11 @@ XMLHttpRequest = function XMLHttpRequest() {
}
this.getResponseHeader = function xhr_getResponseHeader(header) {
return new String();
}
this.getAllResponseHeaders = function xhr_getAllResponseHeaders() {
return new String();
}
};
@ -486,3 +639,10 @@ for(var n = 0; n < dom_nodes.length; n++) {
dom_nodes[n].onreadystatechange();
}
function ActiveXObject() {
this.async = new String();
this.loadXML = function AXOloadXML(url) {
}
}

View File

@ -309,6 +309,10 @@ local_array.prototype = {
res[i] = callback.call(thisArg, this[i], i, this);
res.length = this.length;
return res;
},
item: function Array_prototype_item(index) {
return this[index];
}
};
@ -404,6 +408,13 @@ local_string.prototype = {
loadFile: function loadFile() {
// magic function body handled in analysis.
},
link: function String_prototype_link(url) {
},
anchor: function String_prototype_anchor(url) {
return new String();
}
};
@ -608,3 +619,12 @@ Date.now = function Date_now() {
return new Date().valueOf();
};
function Error(str) {
this.message = new String();
}
function EvalError(str) {
this.message = new String();
}

View File

@ -1,26 +1,35 @@
package com.ibm.wala.cast.js.html;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.List;
import com.ibm.wala.cast.tree.CAstSourcePositionMap.Position;
public class CompositeFileMapping implements FileMapping {
private final FileMapping a;
private final FileMapping b;
private final List<FileMapping> mappings = new ArrayList<FileMapping>(2);
public CompositeFileMapping(FileMapping a, FileMapping b) {
this.a = a;
this.b = b;
addMapping(a);
addMapping(b);
}
private void addMapping(FileMapping fm) {
if (fm instanceof CompositeFileMapping) {
mappings.addAll(((CompositeFileMapping)fm).mappings);
} else {
mappings.add(fm);
}
}
@Override
public IncludedPosition getIncludedPosition(Position line) {
IncludedPosition p = a.getIncludedPosition(line);
if (p != null) {
return p;
} else {
return b.getIncludedPosition(line);
for (FileMapping fm : mappings) {
IncludedPosition result = fm.getIncludedPosition(line);
if (result != null) {
return result;
}
}
return null;
}
@Override
@ -30,6 +39,6 @@ public class CompositeFileMapping implements FileMapping {
}
public String toString() {
return a + "," + b;
return mappings.toString();
}
}

View File

@ -91,13 +91,17 @@ public class DefaultSourceExtractor extends DomLessSourceExtractor{
private void newLine(){
domRegion.println("");
}
private String makeRef(String object, String property) {
return object + "[\"" + property + "\"]";
}
protected void writeElement(ITag tag, String cons, String varName){
Map<String, Pair<String, Position>> attrs = tag.getAllAttributes();
printlnIndented("function make_" + varName + "(parent) {", tag);
stack.push(varName);
printlnIndented("this.temp = " + cons + ";", tag);
printlnIndented("this.temp(\"" + tag.getName() + "\");", tag);
for (Map.Entry<String, Pair<String, Position>> e : attrs.entrySet()){
@ -113,20 +117,23 @@ public class DefaultSourceExtractor extends DomLessSourceExtractor{
} if (tag.getName().equalsIgnoreCase("INPUT")) {
String prop = attrs.containsKey("name") ? attrs.get("name").fst : null;
String type = attrs.containsKey("type") ? attrs.get("type").fst : null;
if (type != null && prop != null) {
if (type.equalsIgnoreCase("RADIO")) {
if (! sets.contains(Pair.make(forms.peek(), prop))) {
sets.add(Pair.make(forms.peek(), prop));
printlnIndented(" currentForm." + prop + " = new Array();", tag);
printlnIndented(" currentForm." + prop + "Counter = 0;", tag);
//input tags do not need to be in a form
if (!forms.isEmpty()) {
if (type.equalsIgnoreCase("RADIO")) {
if (! sets.contains(Pair.make(forms.peek(), prop))) {
sets.add(Pair.make(forms.peek(), prop));
printlnIndented(" " + makeRef("currentForm", prop) + " = new Array();", tag);
printlnIndented(" " + makeRef("currentForm", prop + "Counter") + " = 0;", tag);
}
printlnIndented(" " + makeRef(makeRef("currentForm", prop), prop + "Counter++") + " = this;", tag);
} else {
printlnIndented(" " + makeRef("currentForm", prop) + " = this;", tag);
}
}
printlnIndented(" currentForm." + prop + "[currentForm." + prop + "Counter++] = this;", tag);
} else {
printlnIndented(" currentForm." + prop + " = this;", tag);
}
}
}
printlnIndented(varName + " = this;", tag);
printlnIndented("document." + varName + " = this;", tag);
@ -139,7 +146,8 @@ public class DefaultSourceExtractor extends DomLessSourceExtractor{
}
protected void writeEventAttribute(ITag tag, Position pos, String attr, String value, String varName, String varName2){
if(attr.substring(0,2).equals("on")) {
//There should probably be more checking to see what the attributes are since we allow things like: ; to be used as attributes now.
if(attr.length() >= 2 && attr.substring(0,2).equals("on")) {
printlnIndented(varName + "." + attr + " = function " + tag.getName().toLowerCase() + "_" + attr + "(event) {" + value + "};", tag);
entrypointRegion.println(varName2 + "." + attr + "(null);", tag.getElementPosition(), entrypointUrl);
} else if (value != null) {

View File

@ -23,6 +23,7 @@ import java.util.Map.Entry;
import java.util.Set;
import java.util.regex.Pattern;
import com.ibm.wala.cast.ir.translator.TranslatorToCAst.Error;
import com.ibm.wala.cast.js.html.jericho.JerichoHtmlParser;
import com.ibm.wala.cast.tree.CAstSourcePositionMap.Position;
import com.ibm.wala.util.collections.Pair;
@ -35,6 +36,9 @@ public class DomLessSourceExtractor extends JSSourceExtractor {
}
protected static class HtmlCallback implements IGeneratorCallback{
public static final boolean DEBUG = false;
protected final URL entrypointUrl;
protected final IUrlResolver urlResolver;
@ -131,7 +135,9 @@ public class DomLessSourceExtractor extends JSSourceExtractor {
url = new URL(entrypointUrl, "#" + tag.getElementPosition().getFirstOffset());
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
if (DEBUG) {
e.printStackTrace();
}
}
Position pos = a.getValue().snd;
String attName = a.getKey();
@ -171,7 +177,9 @@ public class DomLessSourceExtractor extends JSSourceExtractor {
}
} catch (IOException e) {
System.err.println("Error reading script file: " + e.getMessage());
if (DEBUG) {
System.err.println("Error reading script file: " + e.getMessage());
}
}
}
@ -182,10 +190,23 @@ public class DomLessSourceExtractor extends JSSourceExtractor {
return;
}
InputStream scriptInputStream = scriptSrc.openConnection().getInputStream();
try{
InputStream scriptInputStream;
try {
scriptInputStream = scriptSrc.openConnection().getInputStream();
} catch (Exception e) {
//it looks like this happens when we can't resolve the url?
if (DEBUG) {
System.err.println("Error reading script: " + scriptSrc);
System.err.println(e);
e.printStackTrace(System.err);
}
return;
}
BufferedReader scriptReader = null;
try {
String line;
BufferedReader scriptReader = new BufferedReader(new UnicodeReader(scriptInputStream, "UTF8"));
scriptReader = new BufferedReader(new UnicodeReader(scriptInputStream, "UTF8"));
StringBuffer x = new StringBuffer();
while ((line = scriptReader.readLine()) != null) {
x.append(line).append("\n");
@ -194,7 +215,9 @@ public class DomLessSourceExtractor extends JSSourceExtractor {
scriptRegion.println(x.toString(), scriptTag.getElementPosition(), scriptSrc);
} finally {
scriptInputStream.close();
if (scriptReader != null) {
scriptReader.close();
}
}
}
@ -223,9 +246,9 @@ public class DomLessSourceExtractor extends JSSourceExtractor {
finalRegion.println("window.__MAIN__();");
}
}
public Set<MappedSourceModule> extractSources(URL entrypointUrl, IHtmlParser htmlParser, IUrlResolver urlResolver)
throws IOException {
throws IOException, Error {
InputStream inputStreamReader = WebUtil.getStream(entrypointUrl);
IGeneratorCallback htmlCallback = createHtmlCallback(entrypointUrl, urlResolver);
@ -237,6 +260,9 @@ public class DomLessSourceExtractor extends JSSourceExtractor {
// writing the final region into one SourceFileModule.
File outputFile = createOutputFile(entrypointUrl, DELETE_UPON_EXIT, USE_TEMP_NAME);
FileMapping fileMapping = finalRegion.writeToFile(new PrintStream(outputFile));
if (fileMapping == null) {
fileMapping = new EmptyFileMapping();
}
MappedSourceModule singleFileModule = new MappedSourceFileModule(outputFile, outputFile.getName(), fileMapping);
return Collections.singleton(singleFileModule);
}
@ -262,7 +288,7 @@ public class DomLessSourceExtractor extends JSSourceExtractor {
}
public static void main(String[] args) throws IOException {
public static void main(String[] args) throws IOException, Error {
// DomLessSourceExtractor domLessScopeGenerator = new DomLessSourceExtractor();
JSSourceExtractor domLessScopeGenerator = new DefaultSourceExtractor();
JSSourceExtractor.DELETE_UPON_EXIT = false;

View File

@ -0,0 +1,19 @@
package com.ibm.wala.cast.js.html;
import java.io.PrintStream;
import com.ibm.wala.cast.tree.CAstSourcePositionMap.Position;
public class EmptyFileMapping implements FileMapping {
@Override
public IncludedPosition getIncludedPosition(Position line) {
return null;
}
@Override
public void dump(PrintStream ps) {
ps.println("empty mapping");
}
}

View File

@ -13,6 +13,8 @@ package com.ibm.wala.cast.js.html;
import java.io.InputStream;
import java.net.URL;
import com.ibm.wala.cast.ir.translator.TranslatorToCAst.Error;
/**
* @author danielk
* @author yinnonh
@ -25,7 +27,8 @@ public interface IHtmlParser {
* @param reader
* @param callback
* @param fileName
* @throws Error
*/
public void parse(URL url, InputStream reader, IHtmlCallback callback, String fileName);
public void parse(URL url, InputStream reader, IHtmlCallback callback, String fileName) throws Error;
}

View File

@ -14,6 +14,8 @@ import java.io.IOException;
import java.net.URL;
import java.util.Set;
import com.ibm.wala.cast.ir.translator.TranslatorToCAst.Error;
/**
* Extracts scripts from a given URL of an HTML. Retrieves also attached js files.
* Provides file and line mapping for each extracted SourceFileModule back to the original file and line number.
@ -23,10 +25,10 @@ import java.util.Set;
*/
public abstract class JSSourceExtractor {
public static boolean DELETE_UPON_EXIT = false;
public static boolean DELETE_UPON_EXIT = true;
public static boolean USE_TEMP_NAME = false;
public static boolean USE_TEMP_NAME = true;
public abstract Set<MappedSourceModule> extractSources(URL entrypointUrl, IHtmlParser htmlParser, IUrlResolver urlResolver) throws IOException;
public abstract Set<MappedSourceModule> extractSources(URL entrypointUrl, IHtmlParser htmlParser, IUrlResolver urlResolver) throws IOException, Error;
}

View File

@ -17,8 +17,8 @@ import java.net.URL;
import java.net.URLConnection;
import java.util.Set;
import com.ibm.wala.cast.ir.translator.TranslatorToCAst.Error;
import com.ibm.wala.cast.js.html.jericho.JerichoHtmlParser;
import com.ibm.wala.util.debug.Assertions;
public class WebUtil {
@ -34,19 +34,7 @@ public class WebUtil {
WebUtil.factory = factory;
}
public static Set<MappedSourceModule> extractScriptFromHTML(String url) {
try {
if (! url.startsWith("file://")) {
url = "file://" + url;
}
return extractScriptFromHTML(new URL(url));
} catch (MalformedURLException e) {
Assertions.UNREACHABLE( e.toString() );
return null;
}
}
public static Set<MappedSourceModule> extractScriptFromHTML(URL url) {
public static Set<MappedSourceModule> extractScriptFromHTML(URL url) throws Error {
try {
JSSourceExtractor extractor = new DefaultSourceExtractor();
return extractor.extractSources(url, factory.getParser(), new IdentityUrlResolver());
@ -55,7 +43,7 @@ public class WebUtil {
}
}
public static void main(String[] args) throws MalformedURLException {
public static void main(String[] args) throws MalformedURLException, Error {
System.err.println(extractScriptFromHTML(new URL(args[0])));
}

View File

@ -15,14 +15,19 @@ import java.io.InputStream;
import java.net.URL;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import net.htmlparser.jericho.Config;
import net.htmlparser.jericho.Element;
import net.htmlparser.jericho.Logger;
import net.htmlparser.jericho.LoggerProvider;
import net.htmlparser.jericho.Source;
import com.ibm.wala.cast.ir.translator.TranslatorToCAst;
import com.ibm.wala.cast.js.html.IHtmlCallback;
import com.ibm.wala.cast.js.html.IHtmlParser;
import com.ibm.wala.util.collections.HashSetFactory;
import com.ibm.wala.util.warnings.Warning;
/**
@ -30,20 +35,87 @@ import com.ibm.wala.cast.js.html.IHtmlParser;
* Uses the Jericho parser to go over the HTML
*/
public class JerichoHtmlParser implements IHtmlParser{
static Set<Warning> warnings = HashSetFactory.make();
static{
Config.LoggerProvider = LoggerProvider.STDERR;
class CAstLoggerProvider implements LoggerProvider {
@Override
public Logger getLogger(String arg0) {
class CAstLogger implements Logger {
@Override
public void debug(String arg0) {
// TODO Auto-generated method stub
}
@Override
public void error(final String arg0) {
warnings.add(new Warning() {
@Override
public String getMsg() {
return arg0;
}
});
}
@Override
public void info(String arg0) {
// TODO Auto-generated method stub
}
@Override
public boolean isDebugEnabled() {
return true;
}
@Override
public boolean isErrorEnabled() {
return true;
}
@Override
public boolean isInfoEnabled() {
return true;
}
@Override
public boolean isWarnEnabled() {
return true;
}
@Override
public void warn(String arg0) {
// TODO Auto-generated method stub
}
}
return new CAstLogger();
}
}
Config.LoggerProvider = new CAstLoggerProvider();
}
public void parse(URL url, InputStream reader, IHtmlCallback callback, String fileName) {
public void parse(URL url, InputStream reader, IHtmlCallback callback, String fileName) throws TranslatorToCAst.Error {
warnings.clear();
Parser parser = new Parser(callback, fileName);
Source src;
try {
src = new Source(reader);
src.setLogger(Config.LoggerProvider.getLogger(fileName));
List<Element> childElements = src.getChildElements();
for (Iterator<Element> nodeIterator = childElements.iterator(); nodeIterator.hasNext();) {
Element e = nodeIterator.next();
parser.parse(e);
}
if (! warnings.isEmpty()) {
throw new TranslatorToCAst.Error(warnings.iterator().next());
}
} catch (IOException e) {
System.err.println("Error parsing file: " + e.getMessage());
}

View File

@ -29,11 +29,9 @@ import com.ibm.wala.ipa.callgraph.ContextKey;
import com.ibm.wala.ipa.callgraph.ContextSelector;
import com.ibm.wala.ipa.callgraph.impl.Everywhere;
import com.ibm.wala.ipa.callgraph.propagation.ConcreteTypeKey;
import com.ibm.wala.ipa.callgraph.propagation.ConstantKey;
import com.ibm.wala.ipa.callgraph.propagation.FilteredPointerKey;
import com.ibm.wala.ipa.callgraph.propagation.FilteredPointerKey.SingleInstanceFilter;
import com.ibm.wala.ipa.callgraph.propagation.InstanceKey;
import com.ibm.wala.ipa.cha.IClassHierarchy;
import com.ibm.wala.ssa.DefUse;
import com.ibm.wala.ssa.IR;
import com.ibm.wala.ssa.IRFactory;
@ -304,29 +302,6 @@ public class ForInContextSelector implements ContextSelector {
return f;
}
// simulate effect of ToString conversion on key
private InstanceKey simulateToString(IClassHierarchy cha, InstanceKey key) {
IClass stringClass = cha.lookupClass(JavaScriptTypes.String);
IClass numberClass = cha.lookupClass(JavaScriptTypes.Number);
if(key instanceof ConstantKey) {
Object value = ((ConstantKey)key).getValue();
if(value instanceof String) {
return key;
} else if(value instanceof Number) {
Double dval = ((Number)value).doubleValue();
return new ConstantKey<Double>(dval, numberClass);
} else if(value instanceof Boolean) {
Boolean bval = (Boolean)value;
return new ConstantKey<String>(bval.toString(), stringClass);
} else if(value == null) {
return new ConstantKey<String>("null", stringClass);
}
} /*else if(key != null && key.getConcreteType() == numberClass) {
return key;
}*/
return new ConcreteTypeKey(stringClass);
}
public Context getCalleeTarget(CGNode caller, CallSiteReference site, IMethod callee, final InstanceKey[] receiver) {
Context baseContext = base.getCalleeTarget(caller, site, callee, receiver);
String calleeFullName = callee.getDeclaringClass().getName().toString();
@ -334,22 +309,18 @@ public class ForInContextSelector implements ContextSelector {
if(USE_NAME_TO_SELECT_CONTEXT) {
if(calleeShortName.contains(HACK_METHOD_STR) && receiver.length > index) {
// we assume that the argument is only used as a property name, so we can do ToString
return new ForInContext(baseContext, simulateToString(caller.getClassHierarchy(), receiver[index]));
return new ForInContext(baseContext, receiver[index]);
}
} else if(receiver.length > index) {
Frequency f = usesFirstArgAsPropertyName(callee);
/*
if(f == Frequency.ALWAYS) {
return new ForInContext(baseContext, simulateToString(caller.getClassHierarchy(), receiver[index]));
} else if(f == Frequency.SOMETIMES) {
*/
if(f == Frequency.ALWAYS|| f == Frequency.SOMETIMES) {
if(receiver[index] == null) {
IClass undef = caller.getClassHierarchy().lookupClass(JavaScriptTypes.Undefined);
return new ForInContext(baseContext, new ConcreteTypeKey(undef));
} else {
return new ForInContext(baseContext, receiver[index]);
}
//}
}
}
if (USE_CPA_IN_BODIES && FORIN_MARKER.equals(caller.getContext().get(FORIN_KEY))) {
return new SelectiveCPAContext(baseContext, receiver);

View File

@ -20,6 +20,7 @@ import java.util.Set;
import com.ibm.wala.cast.ipa.callgraph.StandardFunctionTargetSelector;
import com.ibm.wala.cast.ir.translator.TranslatorToCAst;
import com.ibm.wala.cast.ir.translator.TranslatorToCAst.Error;
import com.ibm.wala.cast.js.loader.JavaScriptLoader;
import com.ibm.wala.cast.js.loader.JavaScriptLoaderFactory;
import com.ibm.wala.cast.js.translator.JSAstTranslator;
@ -182,17 +183,22 @@ public class JSCallGraphUtil extends com.ibm.wala.cast.ipa.callgraph.CAstCallGra
}
}
};
CAstEntity tree = toCAst.translateToCAst();
if (DEBUG) {
CAstPrinter.printTo(tree, new PrintWriter(System.err));
CAstEntity tree;
try {
tree = toCAst.translateToCAst();
if (DEBUG) {
CAstPrinter.printTo(tree, new PrintWriter(System.err));
}
toIR.translate(tree, M);
for (String name : names) {
IClass fcls = cl.lookupClass(name, cha);
cha.addClass(fcls);
}
return names;
} catch (Error e) {
return Collections.emptySet();
}
toIR.translate(tree, M);
for (String name : names) {
IClass fcls = cl.lookupClass(name, cha);
cha.addClass(fcls);
}
return names;
} catch (RuntimeException e) {
} catch (RuntimeException e) {
return Collections.emptySet();
}
}

View File

@ -73,6 +73,9 @@ import com.ibm.wala.ssa.SSAUnaryOpInstruction;
import com.ibm.wala.ssa.SymbolTable;
import com.ibm.wala.types.FieldReference;
import com.ibm.wala.types.TypeReference;
import com.ibm.wala.util.CancelException;
import com.ibm.wala.util.CancelRuntimeException;
import com.ibm.wala.util.MonitorUtil;
import com.ibm.wala.util.collections.HashSetFactory;
import com.ibm.wala.util.intset.IntSet;
import com.ibm.wala.util.intset.IntSetAction;
@ -614,6 +617,11 @@ public class JSSSAPropagationCallGraphBuilder extends AstSSAPropagationCallGraph
rhs.getValue().foreach(new IntSetAction() {
@Override
public void act(int x) {
try {
MonitorUtil.throwExceptionIfCanceled(getBuilder().monitor);
} catch (CancelException e) {
throw new CancelRuntimeException(e);
}
InstanceKey ik = system.getInstanceKey(x);
handleJavascriptDispatch(instruction, ik);
}
@ -732,6 +740,11 @@ public class JSSSAPropagationCallGraphBuilder extends AstSSAPropagationCallGraph
if (isStringConstant(iks1[i])) {
for (int j = 0; j < iks2.length; j++) {
if (isStringConstant(iks2[j])) {
try {
MonitorUtil.throwExceptionIfCanceled(builder.monitor);
} catch (CancelException e) {
throw new CancelRuntimeException(e);
}
String v1 = (String) ((ConstantKey) iks1[i]).getValue();
String v2 = (String) ((ConstantKey) iks2[j]).getValue();
if (v1.indexOf(v2) == -1 && v2.indexOf(v1) == -1) {
@ -757,6 +770,11 @@ public class JSSSAPropagationCallGraphBuilder extends AstSSAPropagationCallGraph
if (doDefault) {
for (int i = 0; i < iks1.length; i++) {
for (int j = 0; j < iks2.length; j++) {
try {
MonitorUtil.throwExceptionIfCanceled(builder.monitor);
} catch (CancelException e) {
throw new CancelRuntimeException(e);
}
if (handleBinaryOperatorArgs(iks1[i], iks2[j])) {
changed = CHANGED;
}

View File

@ -28,6 +28,7 @@ import com.ibm.wala.cast.ipa.callgraph.CAstAnalysisScope;
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.loader.JavaScriptLoader;
@ -53,6 +54,7 @@ import com.ibm.wala.ssa.SSABinaryOpInstruction;
import com.ibm.wala.ssa.SSAInstruction;
import com.ibm.wala.ssa.SSAOptions;
import com.ibm.wala.ssa.SSAPhiInstruction;
import com.ibm.wala.util.WalaException;
import com.ibm.wala.util.collections.HashMapFactory;
import com.ibm.wala.util.collections.Iterator2Iterable;
import com.ibm.wala.util.collections.ObjectArrayMapping;
@ -245,7 +247,12 @@ public class CorrelationFinder {
public Map<IMethod, CorrelationSummary> findCorrelatedAccesses(URL url) throws IOException, ClassHierarchyException {
JavaScriptLoader.addBootstrapFile(WebUtil.preamble);
Set<? extends SourceModule> script = WebUtil.extractScriptFromHTML(url);
Set<? extends SourceModule> script = null;
try {
script = WebUtil.extractScriptFromHTML(url);
} catch (Error e) {
assert false : e.warning;
}
Map<IMethod, CorrelationSummary> summaries = findCorrelatedAccesses(script);
return summaries;
}
@ -256,7 +263,11 @@ public class CorrelationFinder {
WebPageLoaderFactory loaders = new WebPageLoaderFactory(translatorFactory);
CAstAnalysisScope scope = new CAstAnalysisScope(scripts, loaders, Collections.singleton(JavaScriptLoader.JS));
IClassHierarchy cha = ClassHierarchy.make(scope, loaders, JavaScriptLoader.JS);
Util.checkForFrontEndErrors(cha);
try {
Util.checkForFrontEndErrors(cha);
} catch (WalaException e) {
return Collections.emptyMap();
}
IRFactory<IMethod> factory = AstIRFactory.makeDefaultFactory();
Map<IMethod, CorrelationSummary> correlations = HashMapFactory.make();

View File

@ -13,7 +13,6 @@ package com.ibm.wala.cast.js.loader;
import java.io.UnsupportedEncodingException;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@ -72,7 +71,6 @@ import com.ibm.wala.classLoader.IMethod;
import com.ibm.wala.classLoader.Language;
import com.ibm.wala.classLoader.LanguageImpl;
import com.ibm.wala.classLoader.Module;
import com.ibm.wala.classLoader.ModuleEntry;
import com.ibm.wala.classLoader.NewSiteReference;
import com.ibm.wala.classLoader.SourceModule;
import com.ibm.wala.classLoader.SourceURLModule;
@ -652,6 +650,7 @@ public class JavaScriptLoader extends CAstAbstractModuleLoader {
public IClass getSuperclass() {
return null;
}
}
class JavaScriptCodeBody extends AstFunctionClass {
@ -693,7 +692,7 @@ public class JavaScriptLoader extends CAstAbstractModuleLoader {
JavaScriptMethodObject(IClass cls, AbstractCFG cfg, SymbolTable symtab, boolean hasCatchBlock,
TypeReference[][] caughtTypes, boolean hasMonitorOp, AstLexicalInformation lexicalInfo, DebuggingInformation debugInfo) {
super(cls, functionQualifiers, cfg, symtab, AstMethodReference.fnReference(cls.getReference()), hasCatchBlock, caughtTypes,
hasMonitorOp, lexicalInfo, debugInfo);
hasMonitorOp, lexicalInfo, debugInfo, null);
// force creation of these constants by calling the getter methods
symtab.getNullConstant();
@ -925,14 +924,4 @@ public class JavaScriptLoader extends CAstAbstractModuleLoader {
protected boolean shouldTranslate(CAstEntity entity) {
return true;
}
@Override
protected void finishTranslation() {
Iterator<ModuleEntry> ms = getModulesWithParseErrors();
while (ms.hasNext()) {
ModuleEntry m = ms.next();
System.err.println(m);
System.err.println(getMessages(m));
}
}
}

View File

@ -6,11 +6,12 @@ import com.ibm.wala.cast.loader.CAstAbstractLoader;
import com.ibm.wala.classLoader.IClassLoader;
import com.ibm.wala.classLoader.ModuleEntry;
import com.ibm.wala.ipa.cha.IClassHierarchy;
import com.ibm.wala.util.WalaException;
import com.ibm.wala.util.warnings.Warning;
public class Util {
public static void checkForFrontEndErrors(IClassHierarchy cha) {
public static void checkForFrontEndErrors(IClassHierarchy cha) throws WalaException {
StringBuffer message = null;
for(IClassLoader loader : cha.getLoaders()) {
if (loader instanceof CAstAbstractLoader) {
@ -33,7 +34,7 @@ public class Util {
}
if (message != null) {
message.append("end of front end errors\n");
throw new AssertionError(String.valueOf(message));
throw new WalaException(String.valueOf(message));
}
}

View File

@ -612,12 +612,12 @@ public class SSAConversion extends AbstractSSAConversion {
System.err.println(("<<< done " + ir.getMethod()));
return ssa.getComputedLocalMap();
} catch (RuntimeException e) {
System.err.println(("exception " + e + " while converting:"));
System.err.println(ir);
// System.err.println(("exception " + e + " while converting:"));
// System.err.println(ir);
throw e;
} catch (Error e) {
System.err.println(("error " + e + " while converting:"));
System.err.println(ir);
// System.err.println(("error " + e + " while converting:"));
// System.err.println(ir);
throw e;
}
}

View File

@ -74,12 +74,14 @@ import com.ibm.wala.ssa.SymbolTable;
import com.ibm.wala.types.FieldReference;
import com.ibm.wala.types.TypeName;
import com.ibm.wala.types.TypeReference;
import com.ibm.wala.util.collections.HashMapFactory;
import com.ibm.wala.util.collections.HashSetFactory;
import com.ibm.wala.util.collections.MapUtil;
import com.ibm.wala.util.collections.Pair;
import com.ibm.wala.util.debug.Assertions;
import com.ibm.wala.util.graph.INodeWithNumber;
import com.ibm.wala.util.graph.impl.SparseNumberedGraph;
import com.ibm.wala.util.graph.traverse.DFS;
import com.ibm.wala.util.intset.IntSet;
import com.ibm.wala.util.intset.IntSetUtil;
import com.ibm.wala.util.intset.MutableIntSet;
@ -880,6 +882,8 @@ public abstract class AstTranslator extends CAstVisitor<AstTranslator.WalkContex
private final List<PreBasicBlock> blocks = new ArrayList<PreBasicBlock>();
private PreBasicBlock entryBlock;
private final Map<CAstNode, PreBasicBlock> nodeToBlock = new LinkedHashMap<CAstNode, PreBasicBlock>();
private final Map<Object, Set<Pair<PreBasicBlock, Boolean>>> delayedEdges = new LinkedHashMap<Object, Set<Pair<PreBasicBlock, Boolean>>>();
@ -973,6 +977,7 @@ public abstract class AstTranslator extends CAstVisitor<AstTranslator.WalkContex
}
void makeEntryBlock(PreBasicBlock bb) {
entryBlock = bb;
bb.makeEntryBlock();
}
@ -1173,56 +1178,121 @@ public abstract class AstTranslator extends CAstVisitor<AstTranslator.WalkContex
private final SymbolTable symtab;
private interface EdgeOperation {
void act(PreBasicBlock src, PreBasicBlock dst);
}
private void transferEdges(Set<PreBasicBlock> blocks,
IncipientCFG icfg,
EdgeOperation normal,
EdgeOperation except) {
for (PreBasicBlock src : blocks) {
for (Iterator j = icfg.getSuccNodes(src); j.hasNext();) {
PreBasicBlock dst = (PreBasicBlock) j.next();
if (isCatchBlock(dst.getNumber()) || (dst.isExitBlock() && icfg.exceptionalToExit.contains(src))) {
except.act(src, dst);
}
if (dst.isExitBlock() ? icfg.normalToExit.contains(src) : !isCatchBlock(dst.getNumber())) {
normal.act(src, dst);
}
}
}
}
AstCFG(CAstEntity n, IncipientCFG icfg, SymbolTable symtab) {
super(null);
Set<PreBasicBlock> liveBlocks = DFS.getReachableNodes(icfg, Collections.singleton(icfg.entryBlock));
List<PreBasicBlock> blocks = icfg.blocks;
boolean hasDeadBlocks = blocks.size() > liveBlocks.size();
this.symtab = symtab;
functionName = n.getName();
instructionToBlockMap = new int[blocks.size()];
instructionToBlockMap = new int[liveBlocks.size()];
for (int i = 0; i < blocks.size(); i++)
instructionToBlockMap[i] = blocks.get(i).getLastInstructionIndex();
final Map<PreBasicBlock, Collection<PreBasicBlock>> normalEdges =
hasDeadBlocks? HashMapFactory.<PreBasicBlock,Collection<PreBasicBlock>>make() : null;
final Map<PreBasicBlock, Collection<PreBasicBlock>> exceptionalEdges =
hasDeadBlocks? HashMapFactory.<PreBasicBlock,Collection<PreBasicBlock>>make() : null;
if (hasDeadBlocks) {
transferEdges(liveBlocks, icfg, new EdgeOperation() {
public void act(PreBasicBlock src, PreBasicBlock dst) {
if (! normalEdges.containsKey(src)) {
normalEdges.put(src, HashSetFactory.<PreBasicBlock>make());
}
normalEdges.get(src).add(dst);
}
}, new EdgeOperation() {
public void act(PreBasicBlock src, PreBasicBlock dst) {
if (! exceptionalEdges.containsKey(src)) {
exceptionalEdges.put(src, HashSetFactory.<PreBasicBlock>make());
}
exceptionalEdges.get(src).add(dst);
}
});
}
for (int i = 0, blockNumber = 0; i < blocks.size(); i++) {
PreBasicBlock pb = blocks.get(i);
if (liveBlocks.contains(pb)) {
instructionToBlockMap[blockNumber] = blocks.get(i).getLastInstructionIndex();
for (int i = 0; i < blocks.size(); i++) {
PreBasicBlock block = blocks.get(i);
this.addNode(block);
if (block.isCatchBlock()) {
setCatchBlock(i);
PreBasicBlock block = blocks.get(i);
block.setGraphNodeId(-1);
this.addNode(block);
if (block.isCatchBlock()) {
setCatchBlock(blockNumber);
}
if (DEBUG_CFG) {
System.err.println(("added " + blocks.get(i) + " to final CFG as " + getNumber(blocks.get(i))));
}
blockNumber++;
}
if (DEBUG_CFG)
System.err.println(("added " + blocks.get(i) + " to final CFG as " + getNumber(blocks.get(i))));
}
if (DEBUG_CFG)
System.err.println((getMaxNumber() + " blocks total"));
init();
for (int i = 0; i < blocks.size(); i++) {
PreBasicBlock src = blocks.get(i);
for (Iterator j = icfg.getSuccNodes(src); j.hasNext();) {
PreBasicBlock dst = (PreBasicBlock) j.next();
if (isCatchBlock(dst.getNumber()) || (dst.isExitBlock() && icfg.exceptionalToExit.contains(src))) {
if (DEBUG_CFG)
System.err.println(("exceptonal edge " + src + " -> " + dst));
addExceptionalEdge(src, dst);
}
if (dst.isExitBlock() ? icfg.normalToExit.contains(src) : !isCatchBlock(dst.getNumber())) {
if (DEBUG_CFG)
System.err.println(("normal edge " + src + " -> " + dst));
addNormalEdge(src, dst);
if (hasDeadBlocks) {
for (int i = 0; i < blocks.size(); i++) {
PreBasicBlock src = blocks.get(i);
if (liveBlocks.contains(src)) {
if (normalEdges.containsKey(src)) {
for(PreBasicBlock succ : normalEdges.get(src)) {
addNormalEdge(src, succ);
}
}
if (exceptionalEdges.containsKey(src)) {
for(PreBasicBlock succ : exceptionalEdges.get(src)) {
addExceptionalEdge(src, succ);
}
}
}
}
} else {
transferEdges(liveBlocks, icfg, new EdgeOperation() {
public void act(PreBasicBlock src, PreBasicBlock dst) {
addNormalEdge(src, dst);
}
}, new EdgeOperation() {
public void act(PreBasicBlock src, PreBasicBlock dst) {
addExceptionalEdge(src, dst);
}
});
}
int x = 0;
instructions = new SSAInstruction[icfg.currentInstruction];
for (int i = 0; i < blocks.size(); i++) {
List<SSAInstruction> bi = blocks.get(i).instructions();
for (int j = 0; j < bi.size(); j++) {
instructions[x++] = bi.get(j);
if (liveBlocks.contains(blocks.get(i))) {
List<SSAInstruction> bi = blocks.get(i).instructions();
for (int j = 0; j < bi.size(); j++) {
instructions[x++] = bi.get(j);
}
}
}
}

View File

@ -13,14 +13,25 @@ import com.ibm.wala.cast.tree.impl.CAstNodeTypeMapRecorder;
import com.ibm.wala.cast.tree.impl.CAstSourcePositionRecorder;
import com.ibm.wala.cast.tree.rewrite.CAstCloner;
import com.ibm.wala.cast.tree.rewrite.CAstRewriter;
import com.ibm.wala.cast.tree.rewrite.CAstRewriterFactory;
import com.ibm.wala.cast.tree.rewrite.CAstRewriter.CopyKey;
import com.ibm.wala.cast.tree.rewrite.CAstRewriter.RewriteContext;
import com.ibm.wala.cast.tree.rewrite.CAstRewriterFactory;
import com.ibm.wala.util.warnings.Warning;
public interface TranslatorToCAst {
public <C extends RewriteContext<K>, K extends CopyKey<K>> void addRewriter(CAstRewriterFactory<C, K> factory, boolean prepend);
public CAstEntity translateToCAst() throws IOException;
public class Error extends Exception {
public final Warning warning;
public Error(Warning message) {
super(message.getMsg());
warning = message;
}
}
public CAstEntity translateToCAst() throws Error, IOException;
public interface WalkContext<C extends WalkContext<C, T>, T> {

View File

@ -10,6 +10,8 @@
*****************************************************************************/
package com.ibm.wala.cast.loader;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@ -23,6 +25,7 @@ import com.ibm.wala.types.FieldReference;
import com.ibm.wala.types.Selector;
import com.ibm.wala.types.TypeName;
import com.ibm.wala.types.TypeReference;
import com.ibm.wala.types.annotations.Annotation;
import com.ibm.wala.util.strings.Atom;
public abstract class AstDynamicPropertyClass extends AstClass {
@ -89,6 +92,10 @@ public abstract class AstDynamicPropertyClass extends AstClass {
public IClassHierarchy getClassHierarchy() {
return AstDynamicPropertyClass.this.getClassHierarchy();
}
public Collection<Annotation> getAnnotations() {
return Collections.emptySet();
}
});
return declaredFields.get(name);

View File

@ -19,6 +19,7 @@ import com.ibm.wala.classLoader.IField;
import com.ibm.wala.ipa.cha.IClassHierarchy;
import com.ibm.wala.types.FieldReference;
import com.ibm.wala.types.TypeReference;
import com.ibm.wala.types.annotations.Annotation;
import com.ibm.wala.util.strings.Atom;
public class AstField implements IField {
@ -26,16 +27,24 @@ public class AstField implements IField {
private final FieldReference ref;
private final IClass declaringClass;
private final IClassHierarchy cha;
private final Collection<Annotation> annotations;
public AstField(FieldReference ref,
Collection qualifiers,
IClass declaringClass,
IClassHierarchy cha)
IClassHierarchy cha,
Collection<Annotation> annotations)
{
this.declaringClass = declaringClass;
this.qualifiers = qualifiers;
this.ref = ref;
this.cha = cha;
this.annotations = annotations;
}
public Collection<Annotation> getAnnotations() {
return annotations;
}
public IClass getDeclaringClass() {

View File

@ -26,6 +26,7 @@ import com.ibm.wala.types.Descriptor;
import com.ibm.wala.types.MethodReference;
import com.ibm.wala.types.Selector;
import com.ibm.wala.types.TypeReference;
import com.ibm.wala.types.annotations.Annotation;
import com.ibm.wala.util.collections.Pair;
import com.ibm.wala.util.intset.IntSet;
import com.ibm.wala.util.strings.Atom;
@ -113,10 +114,11 @@ public abstract class AstMethod implements IMethod {
private final TypeReference[][] catchTypes;
private final AstLexicalInformation lexicalInfo;
private final DebuggingInformation debugInfo;
private final Collection<Annotation> annotations;
protected AstMethod(IClass cls, Collection qualifiers, AbstractCFG cfg, SymbolTable symtab, MethodReference ref,
boolean hasCatchBlock, TypeReference[][] catchTypes, boolean hasMonitorOp, AstLexicalInformation lexicalInfo,
DebuggingInformation debugInfo) {
DebuggingInformation debugInfo, Collection<Annotation> annotations) {
this.cls = cls;
this.cfg = cfg;
this.ref = ref;
@ -127,12 +129,14 @@ public abstract class AstMethod implements IMethod {
this.hasMonitorOp = hasMonitorOp;
this.lexicalInfo = lexicalInfo;
this.debugInfo = debugInfo;
this.annotations = annotations;
}
protected AstMethod(IClass cls, Collection qualifiers, MethodReference ref) {
protected AstMethod(IClass cls, Collection qualifiers, MethodReference ref, Collection<Annotation> annotations) {
this.cls = cls;
this.qualifiers = qualifiers;
this.ref = ref;
this.annotations = annotations;
this.cfg = null;
this.symtab = null;
@ -173,6 +177,10 @@ public abstract class AstMethod implements IMethod {
return debugInfo;
}
public Collection<Annotation> getAnnotations() {
return annotations;
}
/**
* Parents of this method with respect to lexical scoping, that is, methods
* containing state possibly referenced lexically in this method

View File

@ -139,21 +139,17 @@ public abstract class CAstAbstractModuleLoader extends CAstAbstractLoader {
} else if (moduleEntry instanceof SourceModule) {
TranslatorToCAst xlatorToCAst = getTranslatorToCAst(ast, (SourceModule) moduleEntry);
CAstEntity fileEntity = xlatorToCAst.translateToCAst();
if (fileEntity != null) {
CAstEntity fileEntity = null;
try {
fileEntity = xlatorToCAst.translateToCAst();
if (DEBUG) {
CAstPrinter.printTo(fileEntity, new PrintWriter(System.err));
}
topLevelEntities.add(Pair.make(fileEntity, moduleEntry));
} else {
addMessage(moduleEntry, new Warning(Warning.SEVERE) {
@Override
public String getMsg() {
return "parse error";
}
});
} catch (TranslatorToCAst.Error e) {
addMessage(moduleEntry, e.warning);
}
}
} catch (final MalformedURLException e) {

View File

@ -177,4 +177,5 @@ public interface CAstEntity {
* The CAst type of this entity.
*/
CAstType getType();
}

View File

@ -28,6 +28,8 @@ import com.ibm.wala.util.debug.Assertions;
* TODO: document me.
*/
public abstract class CAstVisitor<C extends CAstVisitor.Context> {
public static boolean DEBUG = true;
private Position currentPosition;
@ -899,15 +901,15 @@ public abstract class CAstVisitor<C extends CAstVisitor.Context> {
switch (n.getKind()) {
case CAstNode.ARRAY_REF: {
if (doVisitArrayRefNode(n, v, a, assign, preOp, context, visitor)) {
return true;
return true;
}
break;
}
case CAstNode.OBJECT_REF: {
if (assign ? visitor.visitObjectRefAssign(n, v, a, context, visitor)
: visitor.visitObjectRefAssignOp(n, v, a, preOp, context, visitor))
if (assign ? visitor.visitObjectRefAssign(n, v, a, context, visitor) : visitor.visitObjectRefAssignOp(n, v, a, preOp,
context, visitor))
return true;
visitor.visit(n.getChild(0), context, visitor);
if (assign)
@ -918,8 +920,8 @@ public abstract class CAstVisitor<C extends CAstVisitor.Context> {
}
case CAstNode.BLOCK_EXPR: {
if (assign ? visitor.visitBlockExprAssign(n, v, a, context, visitor)
: visitor.visitBlockExprAssignOp(n, v, a, preOp, context, visitor))
if (assign ? visitor.visitBlockExprAssign(n, v, a, context, visitor) : visitor.visitBlockExprAssignOp(n, v, a, preOp,
context, visitor))
return true;
// FIXME: is it correct to ignore all the other children?
if (visitor.visitAssignNodes(n.getChild(n.getChildCount() - 1), context, v, a, visitor))
@ -932,8 +934,7 @@ public abstract class CAstVisitor<C extends CAstVisitor.Context> {
}
case CAstNode.VAR: {
if (assign ? visitor.visitVarAssign(n, v, a, context, visitor)
: visitor.visitVarAssignOp(n, v, a, preOp, context, visitor))
if (assign ? visitor.visitVarAssign(n, v, a, context, visitor) : visitor.visitVarAssignOp(n, v, a, preOp, context, visitor))
return true;
if (assign)
visitor.leaveVarAssign(n, v, a, context, visitor);
@ -944,10 +945,10 @@ public abstract class CAstVisitor<C extends CAstVisitor.Context> {
default: {
if (!visitor.doVisitAssignNodes(n, context, v, a, visitor)) {
System.err.println(("cannot handle assign to kind " + n.getKind()));
throw new UnsupportedOperationException(
"cannot handle assignment: " +
CAstPrinter.print(a, context.getSourceMap()));
if (DEBUG) {
System.err.println(("cannot handle assign to kind " + n.getKind()));
}
throw new UnsupportedOperationException("cannot handle assignment: " + CAstPrinter.print(a, context.getSourceMap()));
}
}
}

View File

@ -102,6 +102,458 @@ public interface ContextKey {
new ParameterKey(46),
new ParameterKey(47),
new ParameterKey(48),
new ParameterKey(49)
new ParameterKey(49),
//added based on functions seen in the wild...
//---------
new ParameterKey(50),
new ParameterKey(51),
new ParameterKey(52),
new ParameterKey(53),
new ParameterKey(54),
new ParameterKey(55),
new ParameterKey(56),
new ParameterKey(57),
new ParameterKey(58),
new ParameterKey(59),
new ParameterKey(60),
new ParameterKey(61),
new ParameterKey(62),
new ParameterKey(63),
new ParameterKey(64),
new ParameterKey(65),
new ParameterKey(66),
new ParameterKey(67),
new ParameterKey(68),
new ParameterKey(69),
new ParameterKey(70),
new ParameterKey(71),
new ParameterKey(72),
new ParameterKey(73),
new ParameterKey(74),
new ParameterKey(75),
new ParameterKey(76),
new ParameterKey(77),
new ParameterKey(78),
new ParameterKey(79),
new ParameterKey(80),
new ParameterKey(81),
new ParameterKey(82),
new ParameterKey(83),
new ParameterKey(84),
new ParameterKey(85),
new ParameterKey(86),
new ParameterKey(87),
new ParameterKey(88),
new ParameterKey(89),
new ParameterKey(90),
new ParameterKey(91),
new ParameterKey(92),
new ParameterKey(93),
new ParameterKey(94),
new ParameterKey(95),
new ParameterKey(96),
new ParameterKey(97),
new ParameterKey(98),
new ParameterKey(99),
new ParameterKey(100),
new ParameterKey(101),
new ParameterKey(102),
new ParameterKey(103),
new ParameterKey(104),
new ParameterKey(105),
new ParameterKey(106),
new ParameterKey(107),
new ParameterKey(108),
new ParameterKey(109),
new ParameterKey(110),
new ParameterKey(111),
new ParameterKey(112),
new ParameterKey(113),
new ParameterKey(114),
new ParameterKey(115),
new ParameterKey(116),
new ParameterKey(117),
new ParameterKey(118),
new ParameterKey(119),
new ParameterKey(120),
new ParameterKey(121),
new ParameterKey(122),
new ParameterKey(123),
new ParameterKey(124),
new ParameterKey(125),
new ParameterKey(126),
new ParameterKey(127),
new ParameterKey(128),
new ParameterKey(129),
new ParameterKey(130),
new ParameterKey(131),
new ParameterKey(132),
new ParameterKey(133),
new ParameterKey(134),
new ParameterKey(135),
new ParameterKey(136),
new ParameterKey(137),
new ParameterKey(138),
new ParameterKey(139),
new ParameterKey(140),
new ParameterKey(141),
new ParameterKey(142),
new ParameterKey(143),
new ParameterKey(144),
new ParameterKey(145),
new ParameterKey(146),
new ParameterKey(147),
new ParameterKey(148),
new ParameterKey(149),
new ParameterKey(150),
new ParameterKey(151),
new ParameterKey(152),
new ParameterKey(153),
new ParameterKey(154),
new ParameterKey(155),
new ParameterKey(156),
new ParameterKey(157),
new ParameterKey(158),
new ParameterKey(159),
new ParameterKey(160),
new ParameterKey(161),
new ParameterKey(162),
new ParameterKey(163),
new ParameterKey(164),
new ParameterKey(165),
new ParameterKey(166),
new ParameterKey(167),
new ParameterKey(168),
new ParameterKey(169),
new ParameterKey(170),
new ParameterKey(171),
new ParameterKey(172),
new ParameterKey(173),
new ParameterKey(174),
new ParameterKey(175),
new ParameterKey(176),
new ParameterKey(177),
new ParameterKey(178),
new ParameterKey(179),
new ParameterKey(180),
new ParameterKey(181),
new ParameterKey(182),
new ParameterKey(183),
new ParameterKey(184),
new ParameterKey(185),
new ParameterKey(186),
new ParameterKey(187),
new ParameterKey(188),
new ParameterKey(189),
new ParameterKey(190),
new ParameterKey(191),
new ParameterKey(192),
new ParameterKey(193),
new ParameterKey(194),
new ParameterKey(195),
new ParameterKey(196),
new ParameterKey(197),
new ParameterKey(198),
new ParameterKey(199),
new ParameterKey(200),
new ParameterKey(201),
new ParameterKey(202),
new ParameterKey(203),
new ParameterKey(204),
new ParameterKey(205),
new ParameterKey(206),
new ParameterKey(207),
new ParameterKey(208),
new ParameterKey(209),
new ParameterKey(210),
new ParameterKey(211),
new ParameterKey(212),
new ParameterKey(213),
new ParameterKey(214),
new ParameterKey(215),
new ParameterKey(216),
new ParameterKey(217),
new ParameterKey(218),
new ParameterKey(219),
new ParameterKey(220),
new ParameterKey(221),
new ParameterKey(222),
new ParameterKey(223),
new ParameterKey(224),
new ParameterKey(225),
new ParameterKey(226),
new ParameterKey(227),
new ParameterKey(228),
new ParameterKey(229),
new ParameterKey(230),
new ParameterKey(231),
new ParameterKey(232),
new ParameterKey(233),
new ParameterKey(234),
new ParameterKey(235),
new ParameterKey(236),
new ParameterKey(237),
new ParameterKey(238),
new ParameterKey(239),
new ParameterKey(240),
new ParameterKey(241),
new ParameterKey(242),
new ParameterKey(243),
new ParameterKey(244),
new ParameterKey(245),
new ParameterKey(246),
new ParameterKey(247),
new ParameterKey(248),
new ParameterKey(249),
new ParameterKey(250),
new ParameterKey(251),
new ParameterKey(252),
new ParameterKey(253),
new ParameterKey(254),
new ParameterKey(255),
new ParameterKey(256),
new ParameterKey(257),
new ParameterKey(258),
new ParameterKey(259),
new ParameterKey(260),
new ParameterKey(261),
new ParameterKey(262),
new ParameterKey(263),
new ParameterKey(264),
new ParameterKey(265),
new ParameterKey(266),
new ParameterKey(267),
new ParameterKey(268),
new ParameterKey(269),
new ParameterKey(270),
new ParameterKey(271),
new ParameterKey(272),
new ParameterKey(273),
new ParameterKey(274),
new ParameterKey(275),
new ParameterKey(276),
new ParameterKey(277),
new ParameterKey(278),
new ParameterKey(279),
new ParameterKey(280),
new ParameterKey(281),
new ParameterKey(282),
new ParameterKey(283),
new ParameterKey(284),
new ParameterKey(285),
new ParameterKey(286),
new ParameterKey(287),
new ParameterKey(288),
new ParameterKey(289),
new ParameterKey(290),
new ParameterKey(291),
new ParameterKey(292),
new ParameterKey(293),
new ParameterKey(294),
new ParameterKey(295),
new ParameterKey(296),
new ParameterKey(297),
new ParameterKey(298),
new ParameterKey(299),
new ParameterKey(300),
new ParameterKey(301),
new ParameterKey(302),
new ParameterKey(303),
new ParameterKey(304),
new ParameterKey(305),
new ParameterKey(306),
new ParameterKey(307),
new ParameterKey(308),
new ParameterKey(309),
new ParameterKey(310),
new ParameterKey(311),
new ParameterKey(312),
new ParameterKey(313),
new ParameterKey(314),
new ParameterKey(315),
new ParameterKey(316),
new ParameterKey(317),
new ParameterKey(318),
new ParameterKey(319),
new ParameterKey(320),
new ParameterKey(321),
new ParameterKey(322),
new ParameterKey(323),
new ParameterKey(324),
new ParameterKey(325),
new ParameterKey(326),
new ParameterKey(327),
new ParameterKey(328),
new ParameterKey(329),
new ParameterKey(330),
new ParameterKey(331),
new ParameterKey(332),
new ParameterKey(333),
new ParameterKey(334),
new ParameterKey(335),
new ParameterKey(336),
new ParameterKey(337),
new ParameterKey(338),
new ParameterKey(339),
new ParameterKey(340),
new ParameterKey(341),
new ParameterKey(342),
new ParameterKey(343),
new ParameterKey(344),
new ParameterKey(345),
new ParameterKey(346),
new ParameterKey(347),
new ParameterKey(348),
new ParameterKey(349),
new ParameterKey(350),
new ParameterKey(351),
new ParameterKey(352),
new ParameterKey(353),
new ParameterKey(354),
new ParameterKey(355),
new ParameterKey(356),
new ParameterKey(357),
new ParameterKey(358),
new ParameterKey(359),
new ParameterKey(360),
new ParameterKey(361),
new ParameterKey(362),
new ParameterKey(363),
new ParameterKey(364),
new ParameterKey(365),
new ParameterKey(366),
new ParameterKey(367),
new ParameterKey(368),
new ParameterKey(369),
new ParameterKey(370),
new ParameterKey(371),
new ParameterKey(372),
new ParameterKey(373),
new ParameterKey(374),
new ParameterKey(375),
new ParameterKey(376),
new ParameterKey(377),
new ParameterKey(378),
new ParameterKey(379),
new ParameterKey(380),
new ParameterKey(381),
new ParameterKey(382),
new ParameterKey(383),
new ParameterKey(384),
new ParameterKey(385),
new ParameterKey(386),
new ParameterKey(387),
new ParameterKey(388),
new ParameterKey(389),
new ParameterKey(390),
new ParameterKey(391),
new ParameterKey(392),
new ParameterKey(393),
new ParameterKey(394),
new ParameterKey(395),
new ParameterKey(396),
new ParameterKey(397),
new ParameterKey(398),
new ParameterKey(399),
new ParameterKey(400),
new ParameterKey(401),
new ParameterKey(402),
new ParameterKey(403),
new ParameterKey(404),
new ParameterKey(405),
new ParameterKey(406),
new ParameterKey(407),
new ParameterKey(408),
new ParameterKey(409),
new ParameterKey(410),
new ParameterKey(411),
new ParameterKey(412),
new ParameterKey(413),
new ParameterKey(414),
new ParameterKey(415),
new ParameterKey(416),
new ParameterKey(417),
new ParameterKey(418),
new ParameterKey(419),
new ParameterKey(420),
new ParameterKey(421),
new ParameterKey(422),
new ParameterKey(423),
new ParameterKey(424),
new ParameterKey(425),
new ParameterKey(426),
new ParameterKey(427),
new ParameterKey(428),
new ParameterKey(429),
new ParameterKey(430),
new ParameterKey(431),
new ParameterKey(432),
new ParameterKey(433),
new ParameterKey(434),
new ParameterKey(435),
new ParameterKey(436),
new ParameterKey(437),
new ParameterKey(438),
new ParameterKey(439),
new ParameterKey(440),
new ParameterKey(441),
new ParameterKey(442),
new ParameterKey(443),
new ParameterKey(444),
new ParameterKey(445),
new ParameterKey(446),
new ParameterKey(447),
new ParameterKey(448),
new ParameterKey(449),
new ParameterKey(450),
new ParameterKey(451),
new ParameterKey(452),
new ParameterKey(453),
new ParameterKey(454),
new ParameterKey(455),
new ParameterKey(456),
new ParameterKey(457),
new ParameterKey(458),
new ParameterKey(459),
new ParameterKey(460),
new ParameterKey(461),
new ParameterKey(462),
new ParameterKey(463),
new ParameterKey(464),
new ParameterKey(465),
new ParameterKey(466),
new ParameterKey(467),
new ParameterKey(468),
new ParameterKey(469),
new ParameterKey(470),
new ParameterKey(471),
new ParameterKey(472),
new ParameterKey(473),
new ParameterKey(474),
new ParameterKey(475),
new ParameterKey(476),
new ParameterKey(477),
new ParameterKey(478),
new ParameterKey(479),
new ParameterKey(480),
new ParameterKey(481),
new ParameterKey(482),
new ParameterKey(483),
new ParameterKey(484),
new ParameterKey(485),
new ParameterKey(486),
new ParameterKey(487),
new ParameterKey(488),
new ParameterKey(489),
new ParameterKey(490),
new ParameterKey(491),
new ParameterKey(492),
new ParameterKey(493),
new ParameterKey(494),
new ParameterKey(495),
new ParameterKey(496),
new ParameterKey(497),
new ParameterKey(498),
new ParameterKey(499)
};
}

View File

@ -152,7 +152,7 @@ public abstract class SSAPropagationCallGraphBuilder extends PropagationCallGrap
*/
private final Set<IClass> clinitVisited = HashSetFactory.make();
private IProgressMonitor monitor;
public IProgressMonitor monitor;
protected SSAPropagationCallGraphBuilder(IClassHierarchy cha, AnalysisOptions options, AnalysisCache cache,
PointerKeyFactory pointerKeyFactory) {