get more error information from Rhino

This commit is contained in:
Julian Dolby 2013-11-26 17:20:16 -05:00
parent 7948f3b9ae
commit 026f04cbfc
5 changed files with 26 additions and 11 deletions

View File

@ -19,6 +19,7 @@ import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.mozilla.javascript.CompilerEnvirons;
import org.mozilla.javascript.ErrorReporter;
@ -108,6 +109,7 @@ import com.ibm.wala.cast.tree.impl.CAstSymbolImpl;
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.collections.HashSetFactory;
import com.ibm.wala.util.debug.Assertions;
import com.ibm.wala.util.warnings.Warning;
@ -2289,16 +2291,16 @@ private CAstNode[] walkChildren(final Node n, WalkContext context) {
*/
public CAstEntity translateToCAst() throws Error, IOException, com.ibm.wala.cast.ir.translator.TranslatorToCAst.Error {
class CAstErrorReporter implements ErrorReporter {
private Warning w = null;
private Set<Warning> w = HashSetFactory.make();
@Override
public void error(final String arg0, final String arg1, final int arg2, final String arg3, int arg4) {
w = new Warning(Warning.SEVERE) {
w.add(new Warning(Warning.SEVERE) {
@Override
public String getMsg() {
return arg0 + ": " + arg1 + "@" + arg2 + ": " + arg3;
}
};
});
}
@Override
@ -2327,7 +2329,7 @@ private CAstNode[] walkChildren(final Node n, WalkContext context) {
AstRoot top = P.parse(sourceReader, scriptName, 1);
if (reporter.w != null) {
if (! reporter.w.isEmpty()) {
throw new TranslatorToCAst.Error(reporter.w);
}

View File

@ -44,6 +44,10 @@ public class WebPageLoaderFactory extends JavaScriptLoaderFactory {
return new JSAstTranslator(this) {
private final CAst Ast = new CAstImpl();
private boolean isNestedWithinScriptBody(WalkContext context) {
return isScriptBody(context) || context.getName().contains("__WINDOW_MAIN__");
}
private boolean isScriptBody(WalkContext context) {
return context.top().getName().equals( "__WINDOW_MAIN__" );
}
@ -51,10 +55,10 @@ public class WebPageLoaderFactory extends JavaScriptLoaderFactory {
@Override
protected int doGlobalRead(CAstNode n, WalkContext context, String name) {
int result = context.currentScope().allocateTempValue();
if (isScriptBody(context) && ! "$$undefined".equals(name) && ! "window".equals(name)) {
if (isNestedWithinScriptBody(context) && ! "$$undefined".equals(name) && ! "window".equals(name)) {
// check if field is defined on 'window'
int windowVal = super.doLocalRead(context, "this");
int windowVal = isScriptBody(context)? super.doLocalRead(context, "this"): super.doGlobalRead(n, context, "window");
int isDefined = context.currentScope().allocateTempValue();
context.currentScope().getConstantValue(name);
doIsFieldDefined(context, isDefined, windowVal, Ast.makeConstant(name));

View File

@ -115,7 +115,7 @@ public class JerichoHtmlParser implements IHtmlParser{
parser.parse(e);
}
if (! warnings.isEmpty()) {
throw new TranslatorToCAst.Error(warnings.iterator().next());
throw new TranslatorToCAst.Error(warnings);
}
} catch (IOException e) {
System.err.println("Error parsing file: " + e.getMessage());

View File

@ -14,6 +14,7 @@ import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
import com.ibm.wala.cast.tree.CAst;
import com.ibm.wala.cast.tree.CAstEntity;
@ -33,10 +34,10 @@ public interface TranslatorToCAst {
public <C extends RewriteContext<K>, K extends CopyKey<K>> void addRewriter(CAstRewriterFactory<C, K> factory, boolean prepend);
public class Error extends WalaException {
public final Warning warning;
public final Set<Warning> warning;
public Error(Warning message) {
super(message.getMsg());
public Error(Set<Warning> message) {
super(message.iterator().next().getMsg());
warning = message;
}

View File

@ -65,6 +65,14 @@ public abstract class CAstAbstractLoader implements IClassLoader {
this(cha, null);
}
public void addMessage(ModuleEntry module, Set<Warning> message) {
if (! errors.containsKey(module)) {
errors.put(module, new HashSet<Warning>());
}
errors.get(module).addAll(message);
}
public void addMessage(ModuleEntry module, Warning message) {
if (! errors.containsKey(module)) {
errors.put(module, new HashSet<Warning>());
@ -72,7 +80,7 @@ public abstract class CAstAbstractLoader implements IClassLoader {
errors.get(module).add(message);
}
private Iterator<ModuleEntry> getMessages(final byte severity) {
return new MapIterator<Map.Entry<ModuleEntry,Set<Warning>>, ModuleEntry>(new FilterIterator<Map.Entry<ModuleEntry,Set<Warning>>>(errors.entrySet().iterator(), new Filter<Map.Entry<ModuleEntry,Set<Warning>>>() {
@Override