1.1 --- a/rt/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeParser.java Mon Feb 17 17:49:30 2014 +0100
1.2 +++ b/rt/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeParser.java Tue Feb 18 10:02:46 2014 +0100
1.3 @@ -1261,7 +1261,7 @@
1.4 int name_index;
1.5 int descriptor_index;
1.6 int attributes_count;
1.7 - int value_cpx = 0;
1.8 + int value_cpx = -1;
1.9 boolean isSynthetic = false;
1.10 boolean isDeprecated = false;
1.11 Vector attrs;
1.12 @@ -1382,11 +1382,8 @@
1.13 return isDeprecated;
1.14 }
1.15
1.16 - /**
1.17 - * Returns index of constant value in cpool.
1.18 - */
1.19 - public int getConstantValueIndex() {
1.20 - return (value_cpx);
1.21 + public boolean hasConstantValue() {
1.22 + return value_cpx != -1;
1.23 }
1.24
1.25 /**
2.1 --- a/rt/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java Mon Feb 17 17:49:30 2014 +0100
2.2 +++ b/rt/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java Tue Feb 18 10:02:46 2014 +0100
2.3 @@ -153,8 +153,8 @@
2.4 }
2.5 for (FieldData v : jc.getFields()) {
2.6 if (v.isStatic()) {
2.7 - if ((v.access & ACC_FINAL) != 0) {
2.8 - if (v.getInternalSig().length() == 1) {
2.9 + if ((v.access & ACC_FINAL) != 0 && v.hasConstantValue()) {
2.10 + if (v.getInternalSig().length() == 1 || v.getInternalSig().equals("Ljava/lang/String;")) {
2.11 continue;
2.12 }
2.13 }
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/rt/vm/src/test/java/org/apidesign/vm4brwsr/NoStringCnstntsTest.java Tue Feb 18 10:02:46 2014 +0100
3.3 @@ -0,0 +1,62 @@
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 +
3.22 +package org.apidesign.vm4brwsr;
3.23 +
3.24 +import java.io.IOException;
3.25 +import java.io.InputStream;
3.26 +import static org.testng.Assert.assertEquals;
3.27 +import org.testng.annotations.AfterClass;
3.28 +import org.testng.annotations.BeforeClass;
3.29 +import org.testng.annotations.Test;
3.30 +
3.31 +/**
3.32 + *
3.33 + * @author Jaroslav Tulach <jtulach@netbeans.org>
3.34 + */
3.35 +public class NoStringCnstntsTest {
3.36 + private static String code;
3.37 +
3.38 +
3.39 + @Test public void dontGeneratePrimitiveFinalConstants() {
3.40 + assertEquals(code.indexOf("HELLO"), -1, "MISSING_CONSTANT field should not be generated");
3.41 + }
3.42 +
3.43 + @BeforeClass
3.44 + public static void compileTheCode() throws Exception {
3.45 + final String res = "org/apidesign/vm4brwsr/StringSample";
3.46 + StringBuilder sb = new StringBuilder();
3.47 + class JustStaticMethod implements Bck2Brwsr.Resources {
3.48 + @Override
3.49 + public InputStream get(String resource) throws IOException {
3.50 + final String cn = res + ".class";
3.51 + if (resource.equals(cn)) {
3.52 + return getClass().getClassLoader().getResourceAsStream(cn);
3.53 + }
3.54 + return null;
3.55 + }
3.56 + }
3.57 + Bck2Brwsr.generate(sb, new JustStaticMethod(), res);
3.58 + code = sb.toString();
3.59 + }
3.60 + @AfterClass
3.61 + public static void releaseTheCode() {
3.62 + code = null;
3.63 + }
3.64 +
3.65 +}