1.1 --- a/rt/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java Wed Feb 27 08:37:02 2013 +0100
1.2 +++ b/rt/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java Wed Feb 27 14:38:16 2013 +0100
1.3 @@ -132,6 +132,10 @@
1.4 for (FieldData v : jc.getFields()) {
1.5 if (v.isStatic()) {
1.6 out.append("\n CLS.").append(v.getName()).append(initField(v));
1.7 + out.append("\n c._").append(v.getName()).append(" = function (v) {")
1.8 + .append(" if (arguments.length == 1) CLS.").append(v.getName())
1.9 + .append(" = v; return CLS.").
1.10 + append(v.getName()).append("; };");
1.11 } else {
1.12 out.append("\n c._").append(v.getName()).append(" = function (v) {")
1.13 .append(" if (arguments.length == 1) this.fld_").
1.14 @@ -1244,7 +1248,7 @@
1.15 int indx = readIntArg(byteCodes, i);
1.16 String[] fi = jc.getFieldInfoName(indx);
1.17 final int type = VarType.fromFieldType(fi[2].charAt(0));
1.18 - emit(out, "var @1 = @2(false).constructor.@3;",
1.19 + emit(out, "var @1 = @2(false)._@3();",
1.20 smapper.pushT(type),
1.21 accessClass(fi[0].replace('/', '_')), fi[1]);
1.22 i += 2;
1.23 @@ -1255,7 +1259,7 @@
1.24 int indx = readIntArg(byteCodes, i);
1.25 String[] fi = jc.getFieldInfoName(indx);
1.26 final int type = VarType.fromFieldType(fi[2].charAt(0));
1.27 - emit(out, "@1(false).constructor.@2 = @3;",
1.28 + emit(out, "@1(false)._@2(@3);",
1.29 accessClass(fi[0].replace('/', '_')), fi[1],
1.30 smapper.popT(type));
1.31 i += 2;
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/rt/vm/src/test/java/org/apidesign/vm4brwsr/StaticUseSub.java Wed Feb 27 14:38:16 2013 +0100
2.3 @@ -0,0 +1,24 @@
2.4 +/**
2.5 + * Back 2 Browser Bytecode Translator
2.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
2.7 + *
2.8 + * This program is free software: you can redistribute it and/or modify
2.9 + * it under the terms of the GNU General Public License as published by
2.10 + * the Free Software Foundation, version 2 of the License.
2.11 + *
2.12 + * This program is distributed in the hope that it will be useful,
2.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2.15 + * GNU General Public License for more details.
2.16 + *
2.17 + * You should have received a copy of the GNU General Public License
2.18 + * along with this program. Look for COPYING file in the top folder.
2.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
2.20 + */
2.21 +package org.apidesign.vm4brwsr;
2.22 +
2.23 +public class StaticUseSub extends StaticUse {
2.24 + public static String getNonNull() {
2.25 + return NON_NULL.getClass().getName();
2.26 + }
2.27 +}
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/rt/vm/src/test/java/org/apidesign/vm4brwsr/StaticUseSubTest.java Wed Feb 27 14:38:16 2013 +0100
3.3 @@ -0,0 +1,43 @@
3.4 +/**
3.5 + * Back 2 Browser Bytecode Translator Copyright (C) 2012 Jaroslav Tulach
3.6 + * <jaroslav.tulach@apidesign.org>
3.7 + *
3.8 + * This program is free software: you can redistribute it and/or modify it under
3.9 + * the terms of the GNU General Public License as published by the Free Software
3.10 + * Foundation, version 2 of the License.
3.11 + *
3.12 + * This program is distributed in the hope that it will be useful, but WITHOUT
3.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
3.14 + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
3.15 + * details.
3.16 + *
3.17 + * You should have received a copy of the GNU General Public License along with
3.18 + * this program. Look for COPYING file in the top folder. If not, see
3.19 + * http://opensource.org/licenses/GPL-2.0.
3.20 + */
3.21 +package org.apidesign.vm4brwsr;
3.22 +
3.23 +import org.testng.annotations.BeforeClass;
3.24 +import org.testng.annotations.Test;
3.25 +
3.26 +/**
3.27 + *
3.28 + * @author Jaroslav Tulach <jtulach@netbeans.org>
3.29 + */
3.30 +public class StaticUseSubTest {
3.31 + private static TestVM code;
3.32 +
3.33 + @BeforeClass
3.34 + public static void compileTheCode() throws Exception {
3.35 + StringBuilder sb = new StringBuilder();
3.36 + code = TestVM.compileClass(sb, "org/apidesign/vm4brwsr/StaticUseSub");
3.37 + }
3.38 +
3.39 + @Test public void getInheritedStaticField() throws Exception {
3.40 + code.assertExec(
3.41 + "Obtains non-null", StaticUseSub.class,
3.42 + "getNonNull__Ljava_lang_String_2",
3.43 + "java.lang.Object"
3.44 + );
3.45 + }
3.46 +}
4.1 --- a/rt/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/ReflectionTest.java Wed Feb 27 08:37:02 2013 +0100
4.2 +++ b/rt/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/ReflectionTest.java Wed Feb 27 14:38:16 2013 +0100
4.3 @@ -123,7 +123,7 @@
4.4
4.5 @Compare public String newInstanceFails() throws InstantiationException {
4.6 try {
4.7 - return "success: " + StaticUse.class.newInstance();
4.8 + return "success: " + StaticUseSub.class.newInstance();
4.9 } catch (IllegalAccessException ex) {
4.10 return ex.getClass().getName();
4.11 }
5.1 --- a/rt/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/StaticUse.java Wed Feb 27 08:37:02 2013 +0100
5.2 +++ b/rt/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/StaticUse.java Wed Feb 27 14:38:16 2013 +0100
5.3 @@ -19,7 +19,7 @@
5.4
5.5 class StaticUse {
5.6 public static final Object NON_NULL = new Object();
5.7 - private StaticUse() {
5.8 + StaticUse() {
5.9 }
5.10
5.11 public void instanceMethod() {
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
6.2 +++ b/rt/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/StaticUseSub.java Wed Feb 27 14:38:16 2013 +0100
6.3 @@ -0,0 +1,27 @@
6.4 +/**
6.5 + * Back 2 Browser Bytecode Translator
6.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
6.7 + *
6.8 + * This program is free software: you can redistribute it and/or modify
6.9 + * it under the terms of the GNU General Public License as published by
6.10 + * the Free Software Foundation, version 2 of the License.
6.11 + *
6.12 + * This program is distributed in the hope that it will be useful,
6.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6.15 + * GNU General Public License for more details.
6.16 + *
6.17 + * You should have received a copy of the GNU General Public License
6.18 + * along with this program. Look for COPYING file in the top folder.
6.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
6.20 + */
6.21 +package org.apidesign.bck2brwsr.tck;
6.22 +
6.23 +public class StaticUseSub extends StaticUse {
6.24 + private StaticUseSub() {
6.25 + }
6.26 +
6.27 + public static Object getNonNull() {
6.28 + return NON_NULL;
6.29 + }
6.30 +}
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
7.2 +++ b/rt/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/StaticUseSubTest.java Wed Feb 27 14:38:16 2013 +0100
7.3 @@ -0,0 +1,37 @@
7.4 +/**
7.5 + * Back 2 Browser Bytecode Translator
7.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
7.7 + *
7.8 + * This program is free software: you can redistribute it and/or modify
7.9 + * it under the terms of the GNU General Public License as published by
7.10 + * the Free Software Foundation, version 2 of the License.
7.11 + *
7.12 + * This program is distributed in the hope that it will be useful,
7.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7.15 + * GNU General Public License for more details.
7.16 + *
7.17 + * You should have received a copy of the GNU General Public License
7.18 + * along with this program. Look for COPYING file in the top folder.
7.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
7.20 + */
7.21 +package org.apidesign.bck2brwsr.tck;
7.22 +
7.23 +import org.apidesign.bck2brwsr.vmtest.Compare;
7.24 +import org.apidesign.bck2brwsr.vmtest.VMTest;
7.25 +import org.testng.annotations.Factory;
7.26 +
7.27 +/**
7.28 + *
7.29 + * @author Jaroslav Tulach <jtulach@netbeans.org>
7.30 + */
7.31 +public class StaticUseSubTest {
7.32 + @Compare public String staticFieldInitializationInSuperClass() throws Exception {
7.33 + Object ret = StaticUseSub.getNonNull();
7.34 + return ret.getClass().getName();
7.35 + }
7.36 +
7.37 + @Factory public static Object[] create() {
7.38 + return VMTest.create(StaticUseSubTest.class);
7.39 + }
7.40 +}