Debian Codegraph @

rhino/testsrc/org/mozilla/javascript/tests/FunctionTest.java

raw symbols SCIP
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5 /**
6 *
7 */
8 package org.mozilla.javascript.tests;
9
10 import junit.framework.TestCase;
11
12 import org.mozilla.javascript.Context;
13 import org.mozilla.javascript.ContextAction;
14 import org.mozilla.javascript.Scriptable;
15
16 /**
17 * Unit tests for Function.
18 * @author Marc Guillemot
19 */
20 public class FunctionTest extends TestCase {
21
22 /**
23 * Test for bug #600479
24 * https://bugzilla.mozilla.org/show_bug.cgi?id=600479
25 * Syntax of function built from Function's constructor string parameter was not correct
26 * when this string contained "//".
27 */
28 public void testFunctionWithSlashSlash() {
29 assertEvaluates(true, "new Function('return true//;').call()");
30 }
31
32 private void assertEvaluates(final Object expected, final String source) {
33 final ContextAction action = new ContextAction() {
34 public Object run(Context cx) {
35 final Scriptable scope = cx.initStandardObjects();
36 final Object rep = cx.evaluateString(scope, source, "test.js",
37 0, null);
38 assertEquals(expected, rep);
39 return null;
40 }
41 };
42 Utils.runWithAllOptimizationLevels(action);
43 }
44 }