mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 08:14:09 -08:00
Fix T[].clone()
This commit is contained in:
parent
90cc2c4677
commit
344cb4e42d
|
@ -158,6 +158,7 @@ public class Renderer implements RenderingManager {
|
|||
|
||||
public void renderRuntime() throws RenderingException {
|
||||
try {
|
||||
renderSetCloneMethod();
|
||||
renderRuntimeCls();
|
||||
renderRuntimeString();
|
||||
renderRuntimeUnwrapString();
|
||||
|
@ -172,6 +173,13 @@ public class Renderer implements RenderingManager {
|
|||
}
|
||||
}
|
||||
|
||||
private void renderSetCloneMethod() throws IOException {
|
||||
writer.append("function $rt_setCloneMethod(target, f)").ws().append("{").softNewLine().indent();
|
||||
writer.append("target.").appendMethod("clone", Object.class).ws().append('=').ws().append("f;").
|
||||
softNewLine().indent();
|
||||
writer.outdent().append("}").newLine();
|
||||
}
|
||||
|
||||
private void renderRuntimeCls() throws IOException {
|
||||
writer.append("function $rt_cls(cls)").ws().append("{").softNewLine().indent();
|
||||
writer.append("return ").appendMethodBody("java.lang.Class", "getClass",
|
||||
|
|
|
@ -139,6 +139,9 @@ function $rt_arraycls(cls) {
|
|||
str += "]";
|
||||
return str;
|
||||
};
|
||||
$rt_setCloneMethod(arraycls.prototype, function () {
|
||||
return new arraycls(this.data.slice());
|
||||
});
|
||||
var name = "[" + cls.$meta.binaryName;
|
||||
arraycls.$meta = { item : cls, supertypes : [$rt_objcls()], primitive : false, superclass : $rt_objcls(),
|
||||
name : name, binaryName : name, enum : false };
|
||||
|
|
|
@ -17,6 +17,7 @@ package org.teavm.vm;
|
|||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
import static org.junit.Assert.fail;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
@ -393,4 +394,13 @@ public class VMTest {
|
|||
|
||||
class PathJoint implements FirstPath, SecondPath {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cloneArray() {
|
||||
String[] a = new String[] { "foo" };
|
||||
String[] b = a.clone();
|
||||
assertNotSame(a, b);
|
||||
a[0] = "bar";
|
||||
assertEquals("foo", b[0]);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user