Fix Bug 600479 - SyntaxError with new Function('return true//')

git-svn-id: svn://10.0.0.236/trunk@261317 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
hannes%helma.at 2010-10-02 18:57:31 +00:00
parent 4211f37acd
commit a43d99d7ff
2 changed files with 42 additions and 2 deletions

View File

@ -523,13 +523,13 @@ public class BaseFunction extends IdScriptableObject implements Function
} }
sourceBuf.append(ScriptRuntime.toString(args[i])); sourceBuf.append(ScriptRuntime.toString(args[i]));
} }
sourceBuf.append(") {"); sourceBuf.append(") {\n");
if (arglen != 0) { if (arglen != 0) {
// append function body // append function body
String funBody = ScriptRuntime.toString(args[arglen - 1]); String funBody = ScriptRuntime.toString(args[arglen - 1]);
sourceBuf.append(funBody); sourceBuf.append(funBody);
} }
sourceBuf.append('}'); sourceBuf.append("\n}");
String source = sourceBuf.toString(); String source = sourceBuf.toString();
int[] linep = new int[1]; int[] linep = new int[1];

View File

@ -0,0 +1,40 @@
/**
*
*/
package org.mozilla.javascript.tests;
import junit.framework.TestCase;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.ContextAction;
import org.mozilla.javascript.Scriptable;
/**
* Unit tests for Function.
* @author Marc Guillemot
*/
public class FunctionTest extends TestCase {
/**
* Test for bug #600479
* https://bugzilla.mozilla.org/show_bug.cgi?id=600479
* Syntax of function built from Function's constructor string parameter was not correct
* when this string contained "//".
*/
public void testFunctionWithSlashSlash() {
assertEvaluates(true, "new Function('return true//;').call()");
}
private void assertEvaluates(final Object expected, final String source) {
final ContextAction action = new ContextAction() {
public Object run(Context cx) {
final Scriptable scope = cx.initStandardObjects();
final Object rep = cx.evaluateString(scope, source, "test.js",
0, null);
assertEquals(expected, rep);
return null;
}
};
Utils.runWithAllOptimizationLevels(action);
}
}