improved mechanism for handling 'arguments' array; add model of 'replace' for strings; add new isNullType for Language object
git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@1324 f5eafffb-2e1d-0410-98e4-8ec43c5233c4
This commit is contained in:
parent
03c523a52e
commit
3f8232a725
|
@ -282,6 +282,10 @@ String.prototype = {
|
|||
|
||||
substring: function substring(from, to) {
|
||||
return new String(primitive("StringSubString", this, from, to));
|
||||
},
|
||||
|
||||
replace: function replace(regex, withStr) {
|
||||
return new String(primitive("StringReplace", this, regex, withStr));
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -71,10 +71,18 @@ public class JavaScriptLoader implements IClassLoader {
|
|||
} else if (c == Double.class) {
|
||||
return JavaScriptTypes.Number;
|
||||
} else {
|
||||
assert false : "cannot determine type for " + o + " of class " + c;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isNullType(TypeReference type) {
|
||||
return
|
||||
type.equals(JavaScriptTypes.Undefined)
|
||||
||
|
||||
type.equals(JavaScriptTypes.Null);
|
||||
}
|
||||
};
|
||||
|
||||
private final Map<TypeName,IClass> types = new HashMap<TypeName,IClass>();
|
||||
|
|
|
@ -27,9 +27,8 @@ import com.ibm.wala.cast.js.types.JavaScriptMethods;
|
|||
import com.ibm.wala.cast.js.types.JavaScriptTypes;
|
||||
import com.ibm.wala.cast.loader.AstMethod.DebuggingInformation;
|
||||
import com.ibm.wala.cast.loader.AstMethod.LexicalInformation;
|
||||
import com.ibm.wala.cast.tree.CAstEntity;
|
||||
import com.ibm.wala.cast.tree.CAstNode;
|
||||
import com.ibm.wala.cast.tree.CAstType;
|
||||
import com.ibm.wala.cast.tree.*;
|
||||
import com.ibm.wala.cast.tree.impl.*;
|
||||
import com.ibm.wala.cast.tree.visit.CAstVisitor;
|
||||
import com.ibm.wala.cast.types.AstMethodReference;
|
||||
import com.ibm.wala.cfg.AbstractCFG;
|
||||
|
@ -316,6 +315,16 @@ public class JSAstTranslator extends AstTranslator {
|
|||
}
|
||||
}
|
||||
|
||||
protected void doPrologue(WalkContext context) {
|
||||
super.doPrologue(context);
|
||||
int tempVal = context.currentScope().allocateTempValue();
|
||||
doNewObject(context, null, tempVal, "Array", null);
|
||||
CAstSymbol args = new CAstSymbolImpl("arguments");
|
||||
context.currentScope().declare(args, tempVal);
|
||||
context.cfg().addInstruction(
|
||||
new JavaScriptStaticPropertyWrite(1, "arguments", tempVal));
|
||||
}
|
||||
|
||||
protected boolean doVisit(CAstNode n, Context cntxt, CAstVisitor visitor) {
|
||||
WalkContext context = (WalkContext)cntxt;
|
||||
switch (n.getKind()) {
|
||||
|
|
|
@ -529,18 +529,6 @@ public class RhinoToAstTranslator {
|
|||
stmts = newStmts;
|
||||
}
|
||||
|
||||
// function initialization code
|
||||
if (n instanceof FunctionNode) {
|
||||
CAstNode[] newStmts = new CAstNode[stmts.length + 1];
|
||||
newStmts[0] = Ast.makeNode(CAstNode.DECL_STMT, Ast.makeConstant(new CAstSymbolImpl("arguments", true)), makeBuiltinNew(child,
|
||||
"Object"));
|
||||
|
||||
for (int i = 0; i < stmts.length; i++)
|
||||
newStmts[i + 1] = stmts[i];
|
||||
|
||||
stmts = newStmts;
|
||||
}
|
||||
|
||||
final CAstNode ast = Ast.makeNode(CAstNode.BLOCK_STMT, stmts);
|
||||
final CAstControlFlowMap map = child.cfg();
|
||||
final CAstSourcePositionMap pos = child.pos();
|
||||
|
|
|
@ -49,12 +49,13 @@ public class HTMLCallback extends HTMLEditorKit.ParserCallback {
|
|||
}
|
||||
|
||||
public void handleText(char[] data, int pos) {
|
||||
System.out.println("text pos: " + pos);
|
||||
getScript(data);
|
||||
}
|
||||
|
||||
private void getScript(char [] data) {
|
||||
if(script) {
|
||||
System.out.print(data);
|
||||
System.out.println(new String(data));
|
||||
try {
|
||||
out2.write(data);
|
||||
out2.write("\n");
|
||||
|
@ -65,9 +66,20 @@ public class HTMLCallback extends HTMLEditorKit.ParserCallback {
|
|||
}
|
||||
|
||||
public void handleComment(char[] data, int pos) {
|
||||
System.out.println("comment pos: " + pos);
|
||||
getScript(data);
|
||||
}
|
||||
|
||||
public void handleEndOfLineString(String eol) {
|
||||
if (script) {
|
||||
try {
|
||||
out2.write("\n");
|
||||
} catch (IOException e) {
|
||||
System.out.println("Error writing to second file");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected String createElement(HTML.Tag t, MutableAttributeSet a) {
|
||||
String tag = t.toString().toUpperCase();
|
||||
String varName = "node" + (counter++);
|
||||
|
@ -175,7 +187,4 @@ public class HTMLCallback extends HTMLEditorKit.ParserCallback {
|
|||
System.out.println("Error" + errorMsg);
|
||||
}
|
||||
|
||||
public void handleEndOfLineString(String eol) {
|
||||
System.out.println("EOL");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue