Fixing 238823 : throw explicit IllegalArgumentException when JS source for Context.compileFunction does not contain single JS function statement instead of producing silent empty functions or throwing obscure NullPointerExceptions

This commit is contained in:
igor%mir2.org 2004-03-27 09:35:22 +00:00
Родитель a48a607079
Коммит 03828224aa
1 изменённых файлов: 13 добавлений и 0 удалений

Просмотреть файл

@ -2249,6 +2249,19 @@ public class Context
}
int syntaxErrorCount = compilerEnv.getSyntaxErrorCount();
if (syntaxErrorCount == 0) {
if (returnFunction) {
if (!(tree.getFunctionCount() == 1
&& tree.getFirstChild() != null
&& tree.getFirstChild().getType() == Token.FUNCTION))
{
// XXX: the check just look for the first child
// and allows for more nodes after it for compatibility
// with sources like function() {};;;
throw new IllegalArgumentException(
"compileFunction only accepts source with single JS function: "+sourceString);
}
}
Interpreter compiler = createCompiler();
String encodedSource = p.getEncodedSource();