2626import org .apache .bcel .classfile .ClassParser ;
2727import org .apache .bcel .classfile .JavaClass ;
2828import org .apache .bcel .classfile .Method ;
29+ import org .apache .bcel .generic .BasicType ;
2930import org .apache .bcel .generic .Type ;
3031
3132public class Generator {
@@ -47,15 +48,17 @@ public class Generator {
4748 private final File outputDir ;
4849 private final List <DataRow > libs ;
4950 private final Map <String , JavaClass > classes ;
51+ private final boolean suppressCallJSMethodExceptions ;
5052
5153 public Generator (File outputDir , List <DataRow > libs ) throws IOException {
52- this (outputDir , libs , false );
54+ this (outputDir , libs , false , false );
5355 }
5456
55- public Generator (File outputDir , List <DataRow > libs , boolean throwOnError ) throws IOException {
57+ public Generator (File outputDir , List <DataRow > libs , boolean suppressCallJSMethodExceptions , boolean throwOnError ) throws IOException {
5658 this .outputDir = outputDir ;
5759 this .libs = libs ;
5860 this .classes = readClasses (libs , throwOnError );
61+ this .suppressCallJSMethodExceptions = suppressCallJSMethodExceptions ;
5962 }
6063
6164 public void writeBindings (String filename ) throws IOException , ClassNotFoundException {
@@ -638,6 +641,12 @@ private void writeMethodBody(Method m, boolean isConstructor, boolean isApplicat
638641 }
639642 w .write ("\t \t " );
640643 Type ret = m .getReturnType ();
644+
645+ if (this .suppressCallJSMethodExceptions ) {
646+ w .writeln ("try {" );
647+ w .write ("\t \t \t " );
648+ }
649+
641650 if (!ret .equals (Type .VOID )) {
642651 w .write ("return (" );
643652 writeType (ret , w );
@@ -648,6 +657,19 @@ private void writeMethodBody(Method m, boolean isConstructor, boolean isApplicat
648657 w .write ("\" , " );
649658 writeType (ret , w );
650659 w .writeln (".class, args);" );
660+
661+ if (this .suppressCallJSMethodExceptions ) {
662+ w .writeln ("\t \t } catch (Throwable t) {" );
663+ w .writeln ("\t \t \t android.util.Log.w(\" Error\" , t);" );
664+ if (!ret .equals (Type .VOID )) {
665+ w .write ("\t \t \t " );
666+ w .write ("return " );
667+ w .write (DefaultValues .defaultStringValueFor (ret ));
668+ w .writeln (";" );
669+ }
670+ w .writeln ("\t \t }" );
671+ }
672+
651673 if (m .getName ().equals ("onCreate" ) && isApplicationClass ) {
652674 w .writeln ("\t \t if (runtime != null) {" );
653675 w .writeln ("\t \t \t runtime.run();" );
0 commit comments