forked from mozilla/rhino
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix ClassCastException when using StringBuilder/Buffer mozilla#496 (m…
…ozilla#1210) Convert non-String, non-ConsString objects to a string when creating a ConsString so that StringBuilders and other CharSequence objects can be used natively more easily. Fixes mozilla#1206 and mozilla#496 Co-authored-by: Edward Jensen <[email protected]>
- Loading branch information
1 parent
a7d4e3b
commit e5009c3
Showing
2 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
package org.mozilla.javascript.tests; | ||
|
||
import junit.framework.TestCase; | ||
import org.junit.Test; | ||
import org.mozilla.javascript.Context; | ||
import org.mozilla.javascript.Scriptable; | ||
|
||
/** | ||
* Tests the ConsString class to ensure it properly supports String, StringBuffer and StringBuilder. | ||
*/ | ||
public class Issue1206Test extends TestCase { | ||
@Test | ||
public void testConsStringUsingString() { | ||
Context cx = Context.enter(); | ||
Scriptable scope = cx.initStandardObjects(null); | ||
scope.put("var1", scope, "hello"); | ||
Object result = cx.evaluateString(scope, "var1 = var1 + ' world'", "test", 1, null); | ||
assertEquals("hello world", result); | ||
} | ||
|
||
@Test | ||
public void testConsStringUsingStringBuffer() { | ||
Context cx = Context.enter(); | ||
Scriptable scope = cx.initStandardObjects(null); | ||
scope.put("var1", scope, new StringBuffer("hello")); | ||
Object result = cx.evaluateString(scope, "var1 = var1 + ' world'", "test", 1, null); | ||
assertEquals("hello world", result); | ||
} | ||
|
||
@Test | ||
public void testConsStringUsingStringBuilder() { | ||
Context cx = Context.enter(); | ||
Scriptable scope = cx.initStandardObjects(null); | ||
scope.put("var1", scope, new StringBuilder("hello")); | ||
Object result = cx.evaluateString(scope, "var1 = var1 + ' world'", "test", 1, null); | ||
assertEquals("hello world", result); | ||
} | ||
} |