add modeling of window.onload invocation
This commit is contained in:
parent
81aaa1bee0
commit
898e1c3810
|
@ -0,0 +1,17 @@
|
|||
<HTML>
|
||||
|
||||
<TITLE>Welcome!</TITLE>
|
||||
|
||||
Hi
|
||||
|
||||
<SCRIPT>
|
||||
|
||||
function onload_handler() {}
|
||||
|
||||
window.onload = onload_handler;
|
||||
</SCRIPT>
|
||||
|
||||
<BR>
|
||||
Welcome to our system
|
||||
|
||||
</HTML>
|
File diff suppressed because one or more lines are too long
|
@ -295,7 +295,22 @@ public abstract class TestSimplePageCallGraphShape extends TestJSCallGraphShape
|
|||
CAstCallGraphUtil.dumpCG(builder.getPointerAnalysis(), CG);
|
||||
verifyGraphAssertions(CG, assertionsForWindowx);
|
||||
}
|
||||
|
||||
private static final Object[][] assertionsForWindowOnload = new Object[][] {
|
||||
new Object[] { ROOT, new String[] { "windowonload.html" } },
|
||||
new Object[] { "windowonload.html", new String[] { "windowonload.html/__WINDOW_MAIN__" } },
|
||||
new Object[] { "windowonload.html/__WINDOW_MAIN__", new String[] { "windowonload.html/__WINDOW_MAIN__/onload_handler" } },
|
||||
};
|
||||
|
||||
@Test public void testWindowOnload() throws IOException, IllegalArgumentException, CancelException, WalaException {
|
||||
URL url = getClass().getClassLoader().getResource("pages/windowonload.html");
|
||||
JSCFABuilder builder = JSCallGraphBuilderUtil.makeHTMLCGBuilder(url);
|
||||
CallGraph CG = builder.makeCallGraph(builder.getOptions());
|
||||
CAstCallGraphUtil.dumpCG(builder.getPointerAnalysis(), CG);
|
||||
verifyGraphAssertions(CG, assertionsForWindowOnload);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
@Test public void testJQuery() throws IOException, IllegalArgumentException, CancelException, WalaException {
|
||||
URL url = getClass().getClassLoader().getResource("pages/jquery.html");
|
||||
|
|
|
@ -28,7 +28,10 @@ import com.ibm.wala.cast.js.html.jericho.JerichoHtmlParser;
|
|||
import com.ibm.wala.cast.tree.CAstSourcePositionMap.Position;
|
||||
import com.ibm.wala.util.collections.Pair;
|
||||
|
||||
|
||||
/**
|
||||
* extracts JavaScript source code from HTML, with no model of the actual
|
||||
* DOM data structure
|
||||
*/
|
||||
public class DomLessSourceExtractor extends JSSourceExtractor {
|
||||
private static final Pattern LEGAL_JS_IDENTIFIER_REGEXP = Pattern.compile("[a-zA-Z$_][a-zA-Z\\d$_]*");
|
||||
protected interface IGeneratorCallback extends IHtmlCallback {
|
||||
|
@ -57,8 +60,14 @@ public class DomLessSourceExtractor extends JSSourceExtractor {
|
|||
this.scriptRegion = new SourceRegion();
|
||||
this.domRegion = new SourceRegion();
|
||||
this.entrypointRegion = new SourceRegion();
|
||||
addDefaultHandlerInvocations();
|
||||
}
|
||||
|
||||
private void addDefaultHandlerInvocations() {
|
||||
// always invoke window.onload
|
||||
entrypointRegion.println("window.onload();");
|
||||
}
|
||||
|
||||
protected Position makePos(int lineNumber, ITag governingTag) {
|
||||
return makePos(entrypointUrl, lineNumber, governingTag);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue