From a43d99d7ffa52afa47f23e66ae2dea833419e3e7 Mon Sep 17 00:00:00 2001 From: "hannes%helma.at" Date: Sat, 2 Oct 2010 18:57:31 +0000 Subject: [PATCH] Fix Bug 600479 - SyntaxError with new Function('return true//') git-svn-id: svn://10.0.0.236/trunk@261317 18797224-902f-48f8-a5cc-f745e15eee43 --- .../org/mozilla/javascript/BaseFunction.java | 4 +- .../javascript/tests/FunctionTest.java | 40 +++++++++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 mozilla/js/rhino/testsrc/org/mozilla/javascript/tests/FunctionTest.java diff --git a/mozilla/js/rhino/src/org/mozilla/javascript/BaseFunction.java b/mozilla/js/rhino/src/org/mozilla/javascript/BaseFunction.java index 1d8bfa114ee..51d71a93aaa 100644 --- a/mozilla/js/rhino/src/org/mozilla/javascript/BaseFunction.java +++ b/mozilla/js/rhino/src/org/mozilla/javascript/BaseFunction.java @@ -523,13 +523,13 @@ public class BaseFunction extends IdScriptableObject implements Function } sourceBuf.append(ScriptRuntime.toString(args[i])); } - sourceBuf.append(") {"); + sourceBuf.append(") {\n"); if (arglen != 0) { // append function body String funBody = ScriptRuntime.toString(args[arglen - 1]); sourceBuf.append(funBody); } - sourceBuf.append('}'); + sourceBuf.append("\n}"); String source = sourceBuf.toString(); int[] linep = new int[1]; diff --git a/mozilla/js/rhino/testsrc/org/mozilla/javascript/tests/FunctionTest.java b/mozilla/js/rhino/testsrc/org/mozilla/javascript/tests/FunctionTest.java new file mode 100644 index 00000000000..af0570d8d1a --- /dev/null +++ b/mozilla/js/rhino/testsrc/org/mozilla/javascript/tests/FunctionTest.java @@ -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); + } + }