External classes are treated as exported. closure
authorJaroslav Tulach <jaroslav.tulach@apidesign.org>
Wed, 28 May 2014 14:35:21 +0200
branchclosure
changeset 1611d0df418a5993
parent 1610 a6f807104d8e
child 1612 9979d55fe942
External classes are treated as exported.
rt/vm/src/main/java/org/apidesign/vm4brwsr/VM.java
rt/vm/src/test/java/org/apidesign/vm4brwsr/ImplementExternalInterfaceTest.java
rt/vm/src/test/java/org/apidesign/vm4brwsr/ImplementFactory.java
rt/vm/src/test/java/org/apidesign/vm4brwsr/ImplementInterface.java
rt/vm/src/test/java/org/apidesign/vm4brwsr/TestVM.java
rt/vm/src/test/java/org/apidesign/vm4brwsr/extrnl/ImplementInterface.java
     1.1 --- a/rt/vm/src/main/java/org/apidesign/vm4brwsr/VM.java	Wed May 28 13:38:29 2014 +0200
     1.2 +++ b/rt/vm/src/main/java/org/apidesign/vm4brwsr/VM.java	Wed May 28 14:35:21 2014 +0200
     1.3 @@ -426,7 +426,7 @@
     1.4                              : object + "['" + mangledName + "']";
     1.5      }
     1.6  
     1.7 -    private static final class ExportedMethodFinder
     1.8 +    private final class ExportedMethodFinder
     1.9              implements ClassDataCache.TraversalCallback<MethodData> {
    1.10          private final ExportedSymbols exportedSymbols;
    1.11          private MethodData found;
    1.12 @@ -438,7 +438,10 @@
    1.13          @Override
    1.14          public boolean traverse(final MethodData methodData) {
    1.15              try {
    1.16 -                if (exportedSymbols.isExported(methodData)) {
    1.17 +                if (
    1.18 +                    exportedSymbols.isExported(methodData) ||
    1.19 +                    isExternalClass(methodData.cls.getClassName())
    1.20 +                ) {
    1.21                      found = methodData;
    1.22                      return false;
    1.23                  }
     2.1 --- a/rt/vm/src/test/java/org/apidesign/vm4brwsr/ImplementExternalInterfaceTest.java	Wed May 28 13:38:29 2014 +0200
     2.2 +++ b/rt/vm/src/test/java/org/apidesign/vm4brwsr/ImplementExternalInterfaceTest.java	Wed May 28 14:35:21 2014 +0200
     2.3 @@ -44,7 +44,7 @@
     2.4          StringBuilder sb = new StringBuilder();
     2.5          ScriptEngine[] eng = { null };
     2.6          code = TestVM.compileClassAsExtension(sb, eng, 
     2.7 -            "org/apidesign/vm4brwsr/ImplementInterface", null, null
     2.8 +            "org/apidesign/vm4brwsr/extrnl/ImplementInterface", null, null
     2.9          );
    2.10          code = TestVM.compileClassesAsExtension(sb, eng, null, null,
    2.11              "org/apidesign/vm4brwsr/ImplementFactory", 
     3.1 --- a/rt/vm/src/test/java/org/apidesign/vm4brwsr/ImplementFactory.java	Wed May 28 13:38:29 2014 +0200
     3.2 +++ b/rt/vm/src/test/java/org/apidesign/vm4brwsr/ImplementFactory.java	Wed May 28 14:35:21 2014 +0200
     3.3 @@ -17,6 +17,8 @@
     3.4   */
     3.5  package org.apidesign.vm4brwsr;
     3.6  
     3.7 +import org.apidesign.vm4brwsr.extrnl.ImplementInterface;
     3.8 +
     3.9  /**
    3.10   *
    3.11   * @author Jaroslav Tulach
     4.1 --- a/rt/vm/src/test/java/org/apidesign/vm4brwsr/ImplementInterface.java	Wed May 28 13:38:29 2014 +0200
     4.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.3 @@ -1,26 +0,0 @@
     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;
    4.22 -
    4.23 -/**
    4.24 - *
    4.25 - * @author Jaroslav Tulach
    4.26 - */
    4.27 -public interface ImplementInterface {
    4.28 -    public String sayHello();
    4.29 -}
     5.1 --- a/rt/vm/src/test/java/org/apidesign/vm4brwsr/TestVM.java	Wed May 28 13:38:29 2014 +0200
     5.2 +++ b/rt/vm/src/test/java/org/apidesign/vm4brwsr/TestVM.java	Wed May 28 14:35:21 2014 +0200
     5.3 @@ -26,7 +26,9 @@
     5.4  import java.util.ArrayList;
     5.5  import java.util.Arrays;
     5.6  import java.util.Enumeration;
     5.7 +import java.util.HashSet;
     5.8  import java.util.List;
     5.9 +import java.util.Set;
    5.10  import javax.script.Invocable;
    5.11  import javax.script.ScriptContext;
    5.12  import javax.script.ScriptEngine;
    5.13 @@ -162,6 +164,11 @@
    5.14              eng[0] = js;
    5.15              Bck2Brwsr.generate(sb, new EmulationResources());
    5.16          }
    5.17 +        Set<String> exp = new HashSet<String>();
    5.18 +        for (String n : names) {
    5.19 +            int last = n.lastIndexOf('/');
    5.20 +            exp.add(n.substring(0, last + 1));
    5.21 +        }
    5.22          Bck2Brwsr b2b = Bck2Brwsr.newCompiler().
    5.23              resources(new EmulationResources() {
    5.24                  @Override
    5.25 @@ -174,7 +181,7 @@
    5.26              }).
    5.27              addClasses(names).
    5.28              addResources("org/apidesign/vm4brwsr/obj.js").
    5.29 -            addExported("org/apidesign/vm4brwsr/").
    5.30 +            addExported(exp.toArray(new String[0])).
    5.31              obfuscation(ObfuscationLevel.FULL).
    5.32              library();
    5.33          if (resourceName != null) {
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/rt/vm/src/test/java/org/apidesign/vm4brwsr/extrnl/ImplementInterface.java	Wed May 28 14:35:21 2014 +0200
     6.3 @@ -0,0 +1,26 @@
     6.4 +/**
     6.5 + * Back 2 Browser Bytecode Translator
     6.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
     6.7 + *
     6.8 + * This program is free software: you can redistribute it and/or modify
     6.9 + * it under the terms of the GNU General Public License as published by
    6.10 + * the Free Software Foundation, version 2 of the License.
    6.11 + *
    6.12 + * This program is distributed in the hope that it will be useful,
    6.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    6.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    6.15 + * GNU General Public License for more details.
    6.16 + *
    6.17 + * You should have received a copy of the GNU General Public License
    6.18 + * along with this program. Look for COPYING file in the top folder.
    6.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
    6.20 + */
    6.21 +package org.apidesign.vm4brwsr.extrnl;
    6.22 +
    6.23 +/**
    6.24 + *
    6.25 + * @author Jaroslav Tulach
    6.26 + */
    6.27 +public interface ImplementInterface {
    6.28 +    public String sayHello();
    6.29 +}