Skip to content

Commit

Permalink
Fix ClassCastException when using StringBuilder/Buffer mozilla#496
Browse files Browse the repository at this point in the history
  • Loading branch information
Edward Jensen committed May 20, 2022
1 parent 88de68f commit 503607e
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions testsrc/org/mozilla/javascript/tests/Issue1206Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,40 @@

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 {
public class Issue1206Test extends TestCase {
@Test
public void testConsStringUsingString() {
Context cx = Context.enter();
Scriptable scope = cx.initStandardObjects(null);
scope.put("var1", scope, "hello");
cx.evaluateString(scope, "var1 = var1 + ' world'", "test", 1, null);
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"));
cx.evaluateString(scope, "var1 = var1 + ' world'", "test", 1, null);
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"));
cx.evaluateString(scope, "var1 = var1 + ' world'", "test", 1, null);
Object result = cx.evaluateString(scope, "var1 = var1 + ' world'", "test", 1, null);
assertEquals("hello world", result);
}
}

0 comments on commit 503607e

Please sign in to comment.