Need to make sure an object implements all transitive interfaces, not just those specified directly
1.1 --- a/rt/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java Thu Aug 29 16:49:00 2013 +0000
1.2 +++ b/rt/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java Thu Sep 05 09:36:06 2013 +0200
1.3 @@ -208,14 +208,18 @@
1.4 out.append("\n ").append(destObject).append(".").append(mn).append(".cls = CLS;");
1.5 }
1.6 out.append("\n c.constructor = CLS;");
1.7 + out.append("\n function fillInstOf(x) {");
1.8 String instOfName = "$instOf_" + className;
1.9 - out.append("\n c.").append(instOfName).append(" = true;");
1.10 + out.append("\n x.").append(instOfName).append(" = true;");
1.11 + for (String superInterface : jc.getSuperInterfaces()) {
1.12 + String intrfc = superInterface.replace('/', '_');
1.13 + out.append("\n vm.").append(intrfc).append("(false).fillInstOf(x);");
1.14 + requireReference(superInterface);
1.15 + }
1.16 + out.append("\n }");
1.17 + out.append("\n c.fillInstOf = fillInstOf;");
1.18 + out.append("\n fillInstOf(c);");
1.19 obfuscationDelegate.exportJSProperty(out, "c", instOfName);
1.20 - for (String superInterface : jc.getSuperInterfaces()) {
1.21 - instOfName = "$instOf_" + superInterface.replace('/', '_');
1.22 - out.append("\n c.").append(instOfName).append(" = true;");
1.23 - obfuscationDelegate.exportJSProperty(out, "c", instOfName);
1.24 - }
1.25 out.append("\n CLS.$class = 'temp';");
1.26 out.append("\n CLS.$class = ");
1.27 out.append(accessClass("java_lang_Class(true);"));
2.1 --- a/rt/vm/src/test/java/org/apidesign/vm4brwsr/ClassTest.java Thu Aug 29 16:49:00 2013 +0000
2.2 +++ b/rt/vm/src/test/java/org/apidesign/vm4brwsr/ClassTest.java Thu Sep 05 09:36:06 2013 +0200
2.3 @@ -221,5 +221,11 @@
2.4 "java.lang.Object"
2.5 );
2.6 }
2.7 -
2.8 +
2.9 + @Test public void instanceOfSuperInterface() throws Exception {
2.10 + assertExec("Is iof super interface", Classes.class,
2.11 + "instanceOfSuperInterface__Z",
2.12 + 1.0
2.13 + );
2.14 + }
2.15 }
3.1 --- a/rt/vm/src/test/java/org/apidesign/vm4brwsr/Classes.java Thu Aug 29 16:49:00 2013 +0000
3.2 +++ b/rt/vm/src/test/java/org/apidesign/vm4brwsr/Classes.java Thu Sep 05 09:36:06 2013 +0200
3.3 @@ -18,6 +18,7 @@
3.4 package org.apidesign.vm4brwsr;
3.5
3.6 import java.io.IOException;
3.7 +import java.io.Serializable;
3.8 import java.lang.annotation.Annotation;
3.9 import java.lang.annotation.Retention;
3.10 import java.lang.annotation.RetentionPolicy;
3.11 @@ -240,4 +241,13 @@
3.12
3.13 @JavaScriptBody(args = { }, body = "return function() { alert('x'); };")
3.14 private native static Object fn();
3.15 +
3.16 + public static boolean instanceOfSuperInterface() {
3.17 + Object obj = new SuperSerial() {
3.18 + };
3.19 + return obj instanceof Serializable;
3.20 + }
3.21 +
3.22 + private static interface SuperSerial extends Serializable {
3.23 + }
3.24 }