# HG changeset patch # User Jaroslav Tulach # Date 1392714166 -3600 # Node ID 3775fe162073a1468b206a6a5308da4677801dff # Parent 484248c9c1d68704477cf456608b867f55223454 Don't generate String constants either diff -r 484248c9c1d6 -r 3775fe162073 rt/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeParser.java --- a/rt/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeParser.java Mon Feb 17 17:49:30 2014 +0100 +++ b/rt/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeParser.java Tue Feb 18 10:02:46 2014 +0100 @@ -1261,7 +1261,7 @@ int name_index; int descriptor_index; int attributes_count; - int value_cpx = 0; + int value_cpx = -1; boolean isSynthetic = false; boolean isDeprecated = false; Vector attrs; @@ -1382,11 +1382,8 @@ return isDeprecated; } - /** - * Returns index of constant value in cpool. - */ - public int getConstantValueIndex() { - return (value_cpx); + public boolean hasConstantValue() { + return value_cpx != -1; } /** diff -r 484248c9c1d6 -r 3775fe162073 rt/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java --- a/rt/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java Mon Feb 17 17:49:30 2014 +0100 +++ b/rt/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java Tue Feb 18 10:02:46 2014 +0100 @@ -153,8 +153,8 @@ } for (FieldData v : jc.getFields()) { if (v.isStatic()) { - if ((v.access & ACC_FINAL) != 0) { - if (v.getInternalSig().length() == 1) { + if ((v.access & ACC_FINAL) != 0 && v.hasConstantValue()) { + if (v.getInternalSig().length() == 1 || v.getInternalSig().equals("Ljava/lang/String;")) { continue; } } diff -r 484248c9c1d6 -r 3775fe162073 rt/vm/src/test/java/org/apidesign/vm4brwsr/NoStringCnstntsTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rt/vm/src/test/java/org/apidesign/vm4brwsr/NoStringCnstntsTest.java Tue Feb 18 10:02:46 2014 +0100 @@ -0,0 +1,62 @@ +/** + * Back 2 Browser Bytecode Translator + * Copyright (C) 2012 Jaroslav Tulach + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. Look for COPYING file in the top folder. + * If not, see http://opensource.org/licenses/GPL-2.0. + */ + +package org.apidesign.vm4brwsr; + +import java.io.IOException; +import java.io.InputStream; +import static org.testng.Assert.assertEquals; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * + * @author Jaroslav Tulach + */ +public class NoStringCnstntsTest { + private static String code; + + + @Test public void dontGeneratePrimitiveFinalConstants() { + assertEquals(code.indexOf("HELLO"), -1, "MISSING_CONSTANT field should not be generated"); + } + + @BeforeClass + public static void compileTheCode() throws Exception { + final String res = "org/apidesign/vm4brwsr/StringSample"; + StringBuilder sb = new StringBuilder(); + class JustStaticMethod implements Bck2Brwsr.Resources { + @Override + public InputStream get(String resource) throws IOException { + final String cn = res + ".class"; + if (resource.equals(cn)) { + return getClass().getClassLoader().getResourceAsStream(cn); + } + return null; + } + } + Bck2Brwsr.generate(sb, new JustStaticMethod(), res); + code = sb.toString(); + } + @AfterClass + public static void releaseTheCode() { + code = null; + } + +}