# HG changeset patch # User Jaroslav Tulach # Date 1360844239 -3600 # Node ID 25eba32a96cdc503fab7f222f79833bfc27993b4 # Parent 6ba6b23c1b881b5d6ee0c3567e200c0f42b64d66 Fixing problems with Class.isAssignableFrom reported by David diff -r 6ba6b23c1b88 -r 25eba32a96cd emul/compact/src/test/java/org/apidesign/bck2brwsr/compact/tck/JFXIssuesTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/emul/compact/src/test/java/org/apidesign/bck2brwsr/compact/tck/JFXIssuesTest.java Thu Feb 14 13:17:19 2013 +0100 @@ -0,0 +1,46 @@ +/** + * 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.bck2brwsr.compact.tck; + +import org.apidesign.bck2brwsr.vmtest.Compare; +import org.apidesign.bck2brwsr.vmtest.VMTest; +import org.testng.annotations.Factory; + + +public class JFXIssuesTest { + private abstract class Application { + public abstract int getID(); + } + + private class MyApplication extends Application { + + @Override + public int getID() { + return 1; + } + + } + + @Compare public boolean isClassAssignable() { + return Application.class.isAssignableFrom(MyApplication.class); + } + + @Factory public static Object[] create() { + return VMTest.create(JFXIssuesTest.class); + } +} diff -r 6ba6b23c1b88 -r 25eba32a96cd emul/mini/src/main/java/java/lang/Class.java --- a/emul/mini/src/main/java/java/lang/Class.java Thu Feb 14 12:06:44 2013 +0100 +++ b/emul/mini/src/main/java/java/lang/Class.java Thu Feb 14 13:17:19 2013 +0100 @@ -401,10 +401,15 @@ return cmpType != null && getComponentType().isAssignableFrom(cmpType); } String prop = "$instOf_" + getName().replace('.', '_'); - return hasProperty(cls, prop); + return hasCnstrProperty(cls, prop); } - + @JavaScriptBody(args = { "who", "prop" }, body = + "if (who.cnstr.prototype[prop]) return true; else return false;" + ) + private static native boolean hasCnstrProperty(Object who, String prop); + + /** * Determines if the specified {@code Class} object represents an * interface type. diff -r 6ba6b23c1b88 -r 25eba32a96cd vm/src/test/java/org/apidesign/vm4brwsr/ClassTest.java --- a/vm/src/test/java/org/apidesign/vm4brwsr/ClassTest.java Thu Feb 14 12:06:44 2013 +0100 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/ClassTest.java Thu Feb 14 13:17:19 2013 +0100 @@ -181,5 +181,11 @@ ) throws Exception { StaticMethodTest.assertExec(code, codeSeq, msg, clazz, method, expRes, args); } + @Test public void isClassAssignable() throws Exception { + assertExec("isAssignable works on subclasses", Classes.class, + "isClassAssignable__Z", + true + ); + } } diff -r 6ba6b23c1b88 -r 25eba32a96cd vm/src/test/java/org/apidesign/vm4brwsr/Classes.java --- a/vm/src/test/java/org/apidesign/vm4brwsr/Classes.java Thu Feb 14 12:06:44 2013 +0100 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/Classes.java Thu Feb 14 13:17:19 2013 +0100 @@ -151,4 +151,20 @@ Method m = StaticMethod.class.getMethod("sum", int.class, int.class); return (int) m.invoke(null, a, b); } + + private abstract class Application { + public abstract int getID(); + } + + private class MyApplication extends Application { + @Override + public int getID() { + return 1; + } + } + + public static boolean isClassAssignable() { + return Application.class.isAssignableFrom(MyApplication.class); + } + }