Debian Codegraph @

rhino/testsrc/org/mozilla/javascript/tests/NativeStringTest.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 * @author Marc Guillemot
18 */
19 public class NativeStringTest extends TestCase {
20
21 /**
22 * Test for bug #492359
23 * https://bugzilla.mozilla.org/show_bug.cgi?id=492359
24 * Calling generic String or Array functions without arguments was causing ArrayIndexOutOfBoundsException
25 * in 1.7R2
26 */
27 public void testtoLowerCaseApply() {
28 assertEvaluates("hello", "var x = String.toLowerCase; x.apply('HELLO')");
29 assertEvaluates("hello", "String.toLowerCase('HELLO')"); // first patch proposed to #492359 was breaking this
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 }