1.1 --- a/rt/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java Sun Jan 11 13:20:32 2015 +0100
1.2 +++ b/rt/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java Tue Jan 20 12:26:35 2015 +0100
1.3 @@ -1398,6 +1398,7 @@
1.4 "_" + fi[1], fi)
1.5 );
1.6 i += 2;
1.7 + addReference(fi[0]);
1.8 break;
1.9 }
1.10 case opc_putfield: {
1.11 @@ -1412,6 +1413,7 @@
1.12 accessField(mangleClassAccess + "(false)",
1.13 "_" + fi[1], fi));
1.14 i += 2;
1.15 + addReference(fi[0]);
1.16 break;
1.17 }
1.18 case opc_getstatic: {
2.1 --- a/rt/vm/src/test/java/org/apidesign/vm4brwsr/ImplementFactory.java Sun Jan 11 13:20:32 2015 +0100
2.2 +++ b/rt/vm/src/test/java/org/apidesign/vm4brwsr/ImplementFactory.java Tue Jan 20 12:26:35 2015 +0100
2.3 @@ -18,6 +18,7 @@
2.4 package org.apidesign.vm4brwsr;
2.5
2.6 import org.apidesign.vm4brwsr.extrnl.ImplementInterface;
2.7 +import org.apidesign.vm4brwsr.extrnl.ImportedField;
2.8
2.9 /**
2.10 *
2.11 @@ -35,6 +36,10 @@
2.12 ImplementInterface i = create();
2.13 return i.sayHello();
2.14 }
2.15 +
2.16 + public static int meaning() {
2.17 + return ImportedField.Factory.create(42).x;
2.18 + }
2.19
2.20 private static class Impl implements ImplementInterface {
2.21
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/rt/vm/src/test/java/org/apidesign/vm4brwsr/ImportedFieldTest.java Tue Jan 20 12:26:35 2015 +0100
3.3 @@ -0,0 +1,57 @@
3.4 +/**
3.5 + * Back 2 Browser Bytecode Translator
3.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
3.7 + *
3.8 + * This program is free software: you can redistribute it and/or modify
3.9 + * it under the terms of the GNU General Public License as published by
3.10 + * the Free Software Foundation, version 2 of the License.
3.11 + *
3.12 + * This program is distributed in the hope that it will be useful,
3.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3.15 + * GNU General Public License for more details.
3.16 + *
3.17 + * You should have received a copy of the GNU General Public License
3.18 + * along with this program. Look for COPYING file in the top folder.
3.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
3.20 + */
3.21 +package org.apidesign.vm4brwsr;
3.22 +
3.23 +import javax.script.ScriptEngine;
3.24 +import org.testng.annotations.AfterClass;
3.25 +import org.testng.annotations.BeforeClass;
3.26 +import org.testng.annotations.Test;
3.27 +
3.28 +/** Tests whether we can access public field from a class in extension.
3.29 + *
3.30 + * @author Jaroslav Tulach <jtulach@netbeans.org>
3.31 + */
3.32 +public class ImportedFieldTest {
3.33 + @Test public void checkHello() throws Exception {
3.34 +
3.35 + code.assertExec("Can access field from extension",
3.36 + ImplementFactory.class, "meaning__I",
3.37 + 42
3.38 + );
3.39 + }
3.40 +
3.41 + private static TestVM code;
3.42 +
3.43 + @BeforeClass
3.44 + public static void compileTheCode() throws Exception {
3.45 + StringBuilder sb = new StringBuilder();
3.46 + ScriptEngine[] eng = { null };
3.47 + code = TestVM.compileClassesAsExtension(sb, eng, null, null,
3.48 + "org/apidesign/vm4brwsr/extrnl/ImportedField",
3.49 + "org/apidesign/vm4brwsr/extrnl/ImportedField$Factory"
3.50 + );
3.51 + code = TestVM.compileClassesAsExtension(sb, eng, null, null,
3.52 + "org/apidesign/vm4brwsr/ImplementFactory",
3.53 + "org/apidesign/vm4brwsr/ImplementFactory$Impl"
3.54 + );
3.55 + }
3.56 + @AfterClass
3.57 + public static void releaseTheCode() {
3.58 + code = null;
3.59 + }
3.60 +}
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/rt/vm/src/test/java/org/apidesign/vm4brwsr/extrnl/ImportedField.java Tue Jan 20 12:26:35 2015 +0100
4.3 @@ -0,0 +1,32 @@
4.4 +/**
4.5 + * Back 2 Browser Bytecode Translator
4.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
4.7 + *
4.8 + * This program is free software: you can redistribute it and/or modify
4.9 + * it under the terms of the GNU General Public License as published by
4.10 + * the Free Software Foundation, version 2 of the License.
4.11 + *
4.12 + * This program is distributed in the hope that it will be useful,
4.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4.15 + * GNU General Public License for more details.
4.16 + *
4.17 + * You should have received a copy of the GNU General Public License
4.18 + * along with this program. Look for COPYING file in the top folder.
4.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
4.20 + */
4.21 +package org.apidesign.vm4brwsr.extrnl;
4.22 +
4.23 +public final class ImportedField {
4.24 + public final int x;
4.25 +
4.26 + ImportedField(int x) {
4.27 + this.x = x;
4.28 + }
4.29 +
4.30 + public static final class Factory {
4.31 + public static ImportedField create(int v) {
4.32 + return new ImportedField(v);
4.33 + }
4.34 + }
4.35 +}