Special treatment for net.java.html.lib generated classes Libraries
authorJaroslav Tulach <jaroslav.tulach@apidesign.org>
Tue, 07 Jun 2016 06:20:20 +0200
branchLibraries
changeset 1965973e52d4cabb
parent 1964 668b8501d01f
child 1966 80851e48a68f
Special treatment for net.java.html.lib generated classes
rt/vm/pom.xml
rt/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java
rt/vm/src/main/java/org/apidesign/vm4brwsr/VM.java
rt/vm/src/test/java/org/apidesign/vm4brwsr/LibUse.java
rt/vm/src/test/java/org/apidesign/vm4brwsr/LibUseTest.java
     1.1 --- a/rt/vm/pom.xml	Sat May 21 11:23:01 2016 +0200
     1.2 +++ b/rt/vm/pom.xml	Tue Jun 07 06:20:20 2016 +0200
     1.3 @@ -133,5 +133,10 @@
     1.4        <version>${project.version}</version>
     1.5        <scope>test</scope>
     1.6      </dependency>
     1.7 +    <dependency>
     1.8 +      <groupId>com.dukescript.libraries</groupId>
     1.9 +      <artifactId>net.java.html.lib</artifactId>
    1.10 +      <version>0.3</version>
    1.11 +    </dependency>
    1.12    </dependencies>
    1.13  </project>
     2.1 --- a/rt/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java	Sat May 21 11:23:01 2016 +0200
     2.2 +++ b/rt/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java	Tue Jun 07 06:20:20 2016 +0200
     2.3 @@ -1823,18 +1823,25 @@
     2.4              in.equals("org/netbeans/html/boot/spi/Fn")
     2.5          )) {
     2.6              mcn = "java_lang_Class";
     2.7 +        } else if (in.startsWith("net/java/html/lib/") && in.endsWith("/Exports")) {
     2.8 +            append(mi[1]);
     2.9 +            append('(');
    2.10 +            mcn = null;
    2.11          } else {
    2.12              mcn = mangleClassName(in);
    2.13          }
    2.14 -        String object = accessClassFalse(mcn);
    2.15 -        if (mn.startsWith("cons_")) {
    2.16 -            object += ".constructor";
    2.17 -        }
    2.18 -        append(accessStaticMethod(object, mn, mi));
    2.19 -        if (isStatic) {
    2.20 -            append('(');
    2.21 -        } else {
    2.22 -            append(".call(");
    2.23 +        if (mcn != null) {
    2.24 +            String object = accessClassFalse(mcn);
    2.25 +            if (mn.startsWith("cons_")) {
    2.26 +                object += ".constructor";
    2.27 +            }
    2.28 +            append(accessStaticMethod(object, mn, mi));
    2.29 +            if (isStatic) {
    2.30 +                append('(');
    2.31 +            } else {
    2.32 +                append(".call(");
    2.33 +            }
    2.34 +            addReference(in);
    2.35          }
    2.36          if (numArguments > 0) {
    2.37              append(vars[0]);
    2.38 @@ -1845,7 +1852,6 @@
    2.39          }
    2.40          append(");");
    2.41          i += 2;
    2.42 -        addReference(in);
    2.43          return i;
    2.44      }
    2.45      private int invokeVirtualMethod(byte[] byteCodes, int i, final StackMapper mapper)
     3.1 --- a/rt/vm/src/main/java/org/apidesign/vm4brwsr/VM.java	Sat May 21 11:23:01 2016 +0200
     3.2 +++ b/rt/vm/src/main/java/org/apidesign/vm4brwsr/VM.java	Tue Jun 07 06:20:20 2016 +0200
     3.3 @@ -333,6 +333,9 @@
     3.4      
     3.5      @Override
     3.6      protected boolean requireReference(String cn) {
     3.7 +        if (cn.startsWith("net/java/html/lib/")) {
     3.8 +            return false;
     3.9 +        }
    3.10          return references.addIfMissing(cn);
    3.11      }
    3.12  
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/rt/vm/src/test/java/org/apidesign/vm4brwsr/LibUse.java	Tue Jun 07 06:20:20 2016 +0200
     4.3 @@ -0,0 +1,27 @@
     4.4 +/**
     4.5 + * Back 2 Browser Bytecode Translator
     4.6 + * Copyright (C) 2012-2015 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;
    4.22 +
    4.23 +import net.java.html.lib.Exports;
    4.24 +
    4.25 +public class LibUse {
    4.26 +    public static int fourtyTwo() {
    4.27 +        Number n = (Number) Exports.eval("6 * 7");
    4.28 +        return n.intValue();
    4.29 +    }
    4.30 +}
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/rt/vm/src/test/java/org/apidesign/vm4brwsr/LibUseTest.java	Tue Jun 07 06:20:20 2016 +0200
     5.3 @@ -0,0 +1,40 @@
     5.4 +/**
     5.5 + * Back 2 Browser Bytecode Translator
     5.6 + * Copyright (C) 2012-2015 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
     5.7 + *
     5.8 + * This program is free software: you can redistribute it and/or modify
     5.9 + * it under the terms of the GNU General Public License as published by
    5.10 + * the Free Software Foundation, version 2 of the License.
    5.11 + *
    5.12 + * This program is distributed in the hope that it will be useful,
    5.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    5.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    5.15 + * GNU General Public License for more details.
    5.16 + *
    5.17 + * You should have received a copy of the GNU General Public License
    5.18 + * along with this program. Look for COPYING file in the top folder.
    5.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
    5.20 + */
    5.21 +package org.apidesign.vm4brwsr;
    5.22 +
    5.23 +import org.testng.annotations.AfterClass;
    5.24 +import org.testng.annotations.BeforeClass;
    5.25 +import org.testng.annotations.Test;
    5.26 +
    5.27 +public class LibUseTest {
    5.28 +    private static TestVM code;
    5.29 +
    5.30 +    @BeforeClass
    5.31 +    public static void initVM() throws Exception {
    5.32 +        code = TestVM.compileClass("org/apidesign/vm4brwsr/LibUse");
    5.33 +    }
    5.34 +    @AfterClass
    5.35 +    public static void releaseTheCode() {
    5.36 +        code = null;
    5.37 +    }
    5.38 +
    5.39 +    @Test
    5.40 +    public void fourtyTwo() throws Exception {
    5.41 +        code.assertExec("Fourty two", LibUse.class, "fourtyTwo__I", 42);
    5.42 +    }
    5.43 +}