Make sure Object is always available in each VM and each extension.
1.1 --- a/rt/vm/src/main/java/org/apidesign/vm4brwsr/VM.java Wed May 28 10:47:18 2014 +0200
1.2 +++ b/rt/vm/src/main/java/org/apidesign/vm4brwsr/VM.java Wed May 28 13:38:29 2014 +0200
1.3 @@ -69,6 +69,7 @@
1.4 String[] both = config.classes().toArray();
1.5
1.6 final StringArray fixedNames = new StringArray();
1.7 + fixedNames.add(Object.class.getName().replace('.', '/'));
1.8 fixedNames.add(Class.class.getName().replace('.', '/'));
1.9 fixedNames.add(ArithmeticException.class.getName().replace('.', '/'));
1.10
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/rt/vm/src/test/java/org/apidesign/vm4brwsr/ImplementExternalInterfaceTest.java Wed May 28 13:38:29 2014 +0200
2.3 @@ -0,0 +1,58 @@
2.4 +/**
2.5 + * Back 2 Browser Bytecode Translator
2.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
2.7 + *
2.8 + * This program is free software: you can redistribute it and/or modify
2.9 + * it under the terms of the GNU General Public License as published by
2.10 + * the Free Software Foundation, version 2 of the License.
2.11 + *
2.12 + * This program is distributed in the hope that it will be useful,
2.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2.15 + * GNU General Public License for more details.
2.16 + *
2.17 + * You should have received a copy of the GNU General Public License
2.18 + * along with this program. Look for COPYING file in the top folder.
2.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
2.20 + */
2.21 +package org.apidesign.vm4brwsr;
2.22 +
2.23 +import javax.script.ScriptEngine;
2.24 +import org.testng.annotations.AfterClass;
2.25 +import org.testng.annotations.BeforeClass;
2.26 +import org.testng.annotations.Test;
2.27 +
2.28 +/** Tests whether private impl can implement public interface method
2.29 + * from another extension.
2.30 + *
2.31 + * @author Jaroslav Tulach <jtulach@netbeans.org>
2.32 + */
2.33 +public class ImplementExternalInterfaceTest {
2.34 + @Test public void checkHello() throws Exception {
2.35 + String exp = "Hello!";
2.36 +
2.37 + code.assertExec("Can extension implement class from another extension",
2.38 + ImplementFactory.class, "hello__Ljava_lang_String_2",
2.39 + exp
2.40 + );
2.41 + }
2.42 +
2.43 + private static TestVM code;
2.44 +
2.45 + @BeforeClass
2.46 + public static void compileTheCode() throws Exception {
2.47 + StringBuilder sb = new StringBuilder();
2.48 + ScriptEngine[] eng = { null };
2.49 + code = TestVM.compileClassAsExtension(sb, eng,
2.50 + "org/apidesign/vm4brwsr/ImplementInterface", null, null
2.51 + );
2.52 + code = TestVM.compileClassesAsExtension(sb, eng, null, null,
2.53 + "org/apidesign/vm4brwsr/ImplementFactory",
2.54 + "org/apidesign/vm4brwsr/ImplementFactory$Impl"
2.55 + );
2.56 + }
2.57 + @AfterClass
2.58 + public static void releaseTheCode() {
2.59 + code = null;
2.60 + }
2.61 +}
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/rt/vm/src/test/java/org/apidesign/vm4brwsr/ImplementFactory.java Wed May 28 13:38:29 2014 +0200
3.3 @@ -0,0 +1,47 @@
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 +package org.apidesign.vm4brwsr;
3.22 +
3.23 +/**
3.24 + *
3.25 + * @author Jaroslav Tulach
3.26 + */
3.27 +public class ImplementFactory {
3.28 + private ImplementFactory() {
3.29 + }
3.30 +
3.31 + private static ImplementInterface create() {
3.32 + return new Impl();
3.33 + }
3.34 +
3.35 + public static String hello() {
3.36 + ImplementInterface i = create();
3.37 + return i.sayHello();
3.38 + }
3.39 +
3.40 + private static class Impl implements ImplementInterface {
3.41 +
3.42 + public Impl() {
3.43 + }
3.44 +
3.45 + @Override
3.46 + public String sayHello() {
3.47 + return "Hello!";
3.48 + }
3.49 + }
3.50 +}
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/rt/vm/src/test/java/org/apidesign/vm4brwsr/ImplementInterface.java Wed May 28 13:38:29 2014 +0200
4.3 @@ -0,0 +1,26 @@
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 10:47:18 2014 +0200
5.2 +++ b/rt/vm/src/test/java/org/apidesign/vm4brwsr/TestVM.java Wed May 28 13:38:29 2014 +0200
5.3 @@ -147,6 +147,12 @@
5.4 StringBuilder sb, ScriptEngine[] eng,
5.5 String name, final String resourceName, final String resourceContent
5.6 ) throws ScriptException, IOException {
5.7 + return compileClassesAsExtension(sb, eng, resourceName, resourceContent, name);
5.8 + }
5.9 + static TestVM compileClassesAsExtension(
5.10 + StringBuilder sb, ScriptEngine[] eng,
5.11 + final String resourceName, final String resourceContent, String... names
5.12 + ) throws ScriptException, IOException {
5.13 if (sb == null) {
5.14 sb = new StringBuilder();
5.15 }
5.16 @@ -166,8 +172,9 @@
5.17 return super.get(name);
5.18 }
5.19 }).
5.20 - addRootClasses(name).
5.21 + addClasses(names).
5.22 addResources("org/apidesign/vm4brwsr/obj.js").
5.23 + addExported("org/apidesign/vm4brwsr/").
5.24 obfuscation(ObfuscationLevel.FULL).
5.25 library();
5.26 if (resourceName != null) {