# HG changeset patch # User Jaroslav Tulach # Date 1465273220 -7200 # Node ID 973e52d4cabb4b9a1fd8fb0827b7b33f6de8b7f5 # Parent 668b8501d01f2d660b029a7afe7bd5784834d9bf Special treatment for net.java.html.lib generated classes diff -r 668b8501d01f -r 973e52d4cabb rt/vm/pom.xml --- a/rt/vm/pom.xml Sat May 21 11:23:01 2016 +0200 +++ b/rt/vm/pom.xml Tue Jun 07 06:20:20 2016 +0200 @@ -133,5 +133,10 @@ ${project.version} test + + com.dukescript.libraries + net.java.html.lib + 0.3 + diff -r 668b8501d01f -r 973e52d4cabb rt/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java --- a/rt/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java Sat May 21 11:23:01 2016 +0200 +++ b/rt/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java Tue Jun 07 06:20:20 2016 +0200 @@ -1823,18 +1823,25 @@ in.equals("org/netbeans/html/boot/spi/Fn") )) { mcn = "java_lang_Class"; + } else if (in.startsWith("net/java/html/lib/") && in.endsWith("/Exports")) { + append(mi[1]); + append('('); + mcn = null; } else { mcn = mangleClassName(in); } - String object = accessClassFalse(mcn); - if (mn.startsWith("cons_")) { - object += ".constructor"; - } - append(accessStaticMethod(object, mn, mi)); - if (isStatic) { - append('('); - } else { - append(".call("); + if (mcn != null) { + String object = accessClassFalse(mcn); + if (mn.startsWith("cons_")) { + object += ".constructor"; + } + append(accessStaticMethod(object, mn, mi)); + if (isStatic) { + append('('); + } else { + append(".call("); + } + addReference(in); } if (numArguments > 0) { append(vars[0]); @@ -1845,7 +1852,6 @@ } append(");"); i += 2; - addReference(in); return i; } private int invokeVirtualMethod(byte[] byteCodes, int i, final StackMapper mapper) diff -r 668b8501d01f -r 973e52d4cabb rt/vm/src/main/java/org/apidesign/vm4brwsr/VM.java --- a/rt/vm/src/main/java/org/apidesign/vm4brwsr/VM.java Sat May 21 11:23:01 2016 +0200 +++ b/rt/vm/src/main/java/org/apidesign/vm4brwsr/VM.java Tue Jun 07 06:20:20 2016 +0200 @@ -333,6 +333,9 @@ @Override protected boolean requireReference(String cn) { + if (cn.startsWith("net/java/html/lib/")) { + return false; + } return references.addIfMissing(cn); } diff -r 668b8501d01f -r 973e52d4cabb rt/vm/src/test/java/org/apidesign/vm4brwsr/LibUse.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rt/vm/src/test/java/org/apidesign/vm4brwsr/LibUse.java Tue Jun 07 06:20:20 2016 +0200 @@ -0,0 +1,27 @@ +/** + * Back 2 Browser Bytecode Translator + * Copyright (C) 2012-2015 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 net.java.html.lib.Exports; + +public class LibUse { + public static int fourtyTwo() { + Number n = (Number) Exports.eval("6 * 7"); + return n.intValue(); + } +} diff -r 668b8501d01f -r 973e52d4cabb rt/vm/src/test/java/org/apidesign/vm4brwsr/LibUseTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rt/vm/src/test/java/org/apidesign/vm4brwsr/LibUseTest.java Tue Jun 07 06:20:20 2016 +0200 @@ -0,0 +1,40 @@ +/** + * Back 2 Browser Bytecode Translator + * Copyright (C) 2012-2015 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 org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class LibUseTest { + private static TestVM code; + + @BeforeClass + public static void initVM() throws Exception { + code = TestVM.compileClass("org/apidesign/vm4brwsr/LibUse"); + } + @AfterClass + public static void releaseTheCode() { + code = null; + } + + @Test + public void fourtyTwo() throws Exception { + code.assertExec("Fourty two", LibUse.class, "fourtyTwo__I", 42); + } +}