1.1 --- a/src/main/java/org/apidesign/java4browser/ByteCodeToJavaScript.java Thu Sep 20 09:29:42 2012 +0200
1.2 +++ b/src/main/java/org/apidesign/java4browser/ByteCodeToJavaScript.java Thu Sep 20 10:26:59 2012 +0200
1.3 @@ -355,6 +355,20 @@
1.4 i += 2;
1.5 break;
1.6 }
1.7 + case bc_ifnonnull: {
1.8 + int indx = i + readIntArg(byteCodes, i);
1.9 + out.append("if (stack.pop()) { gt = " + indx);
1.10 + out.append("; continue; }");
1.11 + i += 2;
1.12 + break;
1.13 + }
1.14 + case bc_ifnull: {
1.15 + int indx = i + readIntArg(byteCodes, i);
1.16 + out.append("if (!stack.pop()) { gt = " + indx);
1.17 + out.append("; continue; }");
1.18 + i += 2;
1.19 + break;
1.20 + }
1.21 case bc_if_icmpne:
1.22 i = generateIf(byteCodes, i, "!=");
1.23 break;
1.24 @@ -494,12 +508,17 @@
1.25 sig.insert(firstPos, 'V');
1.26 continue;
1.27 case 'L':
1.28 - i = descriptor.indexOf(';', i);
1.29 + int next = descriptor.indexOf(';', i);
1.30 if (count) {
1.31 cnt++;
1.32 + sig.append(ch);
1.33 + sig.append(descriptor.substring(i, next).replace('/', '_'));
1.34 } else {
1.35 + sig.insert(firstPos, descriptor.substring(i, next).replace('/', '_'));
1.36 + sig.insert(firstPos, ch);
1.37 hasReturnType[0] = true;
1.38 }
1.39 + i = next + 1;
1.40 continue;
1.41 case '[':
1.42 //arrays++;
1.43 @@ -523,11 +542,11 @@
1.44 out.append("consV"); // NOI18N
1.45 } else {
1.46 out.append(m.getName());
1.47 - out.append(m.getReturnType());
1.48 + outType(m.getReturnType(), out);
1.49 }
1.50 List<Parameter> args = m.getParameters();
1.51 for (Parameter t : args) {
1.52 - out.append(t.getDescriptor());
1.53 + outType(t.getDescriptor(), out);
1.54 }
1.55 return out.toString();
1.56 }
1.57 @@ -611,4 +630,13 @@
1.58 i += 2;
1.59 return i;
1.60 }
1.61 +
1.62 + private void outType(final String d, StringBuilder out) {
1.63 + if (d.charAt(0) == 'L') {
1.64 + assert d.charAt(d.length() - 1) == ';';
1.65 + out.append(d.replace('/', '_').substring(0, d.length() - 1));
1.66 + } else {
1.67 + out.append(d);
1.68 + }
1.69 + }
1.70 }
2.1 --- a/src/test/java/org/apidesign/java4browser/Instance.java Thu Sep 20 09:29:42 2012 +0200
2.2 +++ b/src/test/java/org/apidesign/java4browser/Instance.java Thu Sep 20 10:26:59 2012 +0200
2.3 @@ -53,4 +53,17 @@
2.4 GetByte i = new InstanceSub(7, 2.2d);
2.5 return i.getByte();
2.6 }
2.7 + public static boolean instanceOf(boolean sub) {
2.8 + Instance i = createInstance(sub);
2.9 + return isInstanceSubOf(i);
2.10 + }
2.11 + private static boolean isInstanceSubOf(Instance instance) {
2.12 + return instance instanceof InstanceSub;
2.13 + }
2.14 + private static Instance createInstance(boolean sub) {
2.15 + return sub ? new InstanceSub(3, 0) : new Instance();
2.16 + }
2.17 + private static boolean isNull() {
2.18 + return createInstance(true) == null;
2.19 + }
2.20 }
3.1 --- a/src/test/java/org/apidesign/java4browser/InstanceTest.java Thu Sep 20 09:29:42 2012 +0200
3.2 +++ b/src/test/java/org/apidesign/java4browser/InstanceTest.java Thu Sep 20 10:26:59 2012 +0200
3.3 @@ -49,7 +49,31 @@
3.4 Double.valueOf(31)
3.5 );
3.6 }
3.7 -
3.8 +
3.9 + @Test public void isNull() throws Exception {
3.10 + assertExec(
3.11 + "Yes, we are instance",
3.12 + "org_apidesign_java4browser_Instance_isNullZ",
3.13 + Double.valueOf(0.0)
3.14 + );
3.15 + }
3.16 + /*
3.17 + @Test public void isInstanceOf() throws Exception {
3.18 + assertExec(
3.19 + "Yes, we are instance",
3.20 + "org_apidesign_java4browser_Instance_instanceOfZZ",
3.21 + Double.valueOf(1.0), true
3.22 + );
3.23 + }
3.24 +
3.25 + @Test public void notInstanceOf() throws Exception {
3.26 + assertExec(
3.27 + "No, we are not an instance",
3.28 + "org_apidesign_java4browser_Instance_instanceOfZZ",
3.29 + Double.valueOf(0.0), false
3.30 + );
3.31 + }
3.32 + */
3.33 private static void assertExec(String msg, String methodName, Object expRes, Object... args) throws Exception {
3.34 StringBuilder sb = new StringBuilder();
3.35 Invocable i = StaticMethodTest.compileClass(sb, "Instance.class", "InstanceSub.class");