Ejemplo n.º 1
0
  public void testTryCatch() throws Exception {
    recordFileNamesProp.setValue("true");
    recordLineNumbersProp.setValue("true");

    JsProgram program =
        compileClass(
            "package test;",
            "public class EntryPoint {",
            "  public static void onModuleLoad() {",
            "    try {",
            "      throw new RuntimeException();",
            "    } catch (RuntimeException e) {",
            "      String s = e.getMessage();",
            "    }",
            "  }",
            "}");

    // Note: it's up to the catch block to fix $stackDepth.
    checkOnModuleLoad(
        program,
        "function onModuleLoad(){"
            + "var stackIndex;$stack[stackIndex=++$stackDepth]=onModuleLoad;"
            + "$location[stackIndex]='EntryPoint.java:'+'3',$clinit_EntryPoint();var e,s;"
            + "try{throw toJs(($location[stackIndex]='EntryPoint.java:'+'5',new RuntimeException))"
            + "}catch($e0){$e0=toJava($e0);"
            + "$stackDepth=($location[stackIndex]='EntryPoint.java:'+'6',stackIndex);"
            + "if(instanceOf($e0,'java.lang.RuntimeException')){"
            + "e=$e0;s=($location[stackIndex]='EntryPoint.java:'+'7',e).getMessage()}"
            + "else throw toJs(($location[stackIndex]='EntryPoint.java:'+'6',$e0))}"
            + "$stackDepth=stackIndex-1"
            + "}");
  }
Ejemplo n.º 2
0
  public void testThrowWithChainedMethodCall() throws Exception {
    recordFileNamesProp.setValue("true");
    recordLineNumbersProp.setValue("true");
    inline = true;

    JsProgram program =
        compileClass(
            "package test;",
            "public class EntryPoint {",
            "  static Factory factory;",
            "  static Factory getFactory() {",
            "    return factory;", // line 5
            "  }",
            "  public static void onModuleLoad() {", // line 7
            "    throw getFactory().makeException();", // line 8
            "  }",
            "  static class Factory {",
            "    RuntimeException makeException() {",
            "      return new RuntimeException();",
            "    }",
            "  }",
            "}");

    checkOnModuleLoad(
        program,
        "function onModuleLoad(){"
            + "var stackIndex;$stack[stackIndex=++$stackDepth]=onModuleLoad;"
            + "$location[stackIndex]='EntryPoint.java:'+'7',$clinit_EntryPoint();"
            + "throw toJs(($tmp=($location[stackIndex]='EntryPoint.java:'+'5',factory),"
            + "$location[stackIndex]='EntryPoint.java:'+'8',$tmp).makeException())"
            + "}");
  }
Ejemplo n.º 3
0
  public void testThrowWithInlineMethodCall() throws Exception {
    recordFileNamesProp.setValue("true");
    recordLineNumbersProp.setValue("true");
    inline = true;

    JsProgram program =
        compileClass(
            "package test;",
            "public class EntryPoint {",
            "  static Object thing = \"hello\";",
            "  private static String message() { return thing", // line 4
            "    .toString(); }",
            "  public static void onModuleLoad() {", // line 6
            "    throw new RuntimeException(message());", // line 7
            "  }",
            "}");

    // Line 7 should be current when the RuntimeException constructor is called.
    checkOnModuleLoad(
        program,
        "function onModuleLoad(){"
            + "var stackIndex;$stack[stackIndex=++$stackDepth]=onModuleLoad;"
            + "$location[stackIndex]='EntryPoint.java:'+'6',$clinit_EntryPoint();"
            + "throw toJs(new RuntimeException("
            + "($tmp=($location[stackIndex]='EntryPoint.java:'+'4',thing).toString(),"
            + "$location[stackIndex]='EntryPoint.java:'+'7',$tmp)))"
            + "}");
  }
Ejemplo n.º 4
0
 private static boolean maybeOverrideConfig(ModuleDef module, String propName, String newValue) {
   ConfigurationProperty config = module.getProperties().findConfigProp(propName);
   if (config != null) {
     config.setValue(newValue);
     return true;
   }
   return false;
 }
Ejemplo n.º 5
0
  public void testEmptyMethod() throws Exception {
    recordFileNamesProp.setValue("true");
    recordLineNumbersProp.setValue("true");

    JsProgram program =
        compileClass(
            "package test;",
            "public class EntryPoint {",
            "  public static void onModuleLoad() {",
            "  }",
            "}");

    checkOnModuleLoad(
        program,
        "function onModuleLoad(){"
            + "var stackIndex;$stack[stackIndex=++$stackDepth]=onModuleLoad;"
            + "$location[stackIndex]='EntryPoint.java:'+'3',$clinit_EntryPoint();"
            + "$stackDepth=stackIndex-1}");
  }
Ejemplo n.º 6
0
  public void testSimpleThrow() throws Exception {
    recordFileNamesProp.setValue("true");
    recordLineNumbersProp.setValue("true");

    JsProgram program =
        compileClass(
            "package test;",
            "public class EntryPoint {",
            "  public static void onModuleLoad() {",
            "    throw new RuntimeException();",
            "  }",
            "}");

    // Note: it's up to the catch block to fix $stackDepth.
    checkOnModuleLoad(
        program,
        "function onModuleLoad(){"
            + "var stackIndex;$stack[stackIndex=++$stackDepth]=onModuleLoad;"
            + "$location[stackIndex]='EntryPoint.java:'+'3',$clinit_EntryPoint();"
            + "throw toJs(($location[stackIndex]='EntryPoint.java:'+'4',new RuntimeException))"
            + "}");
  }
Ejemplo n.º 7
0
  public void testCallWithArguments() throws Exception {
    recordFileNamesProp.setValue("true");
    recordLineNumbersProp.setValue("true");

    JsProgram program =
        compileClass(
            "package test;",
            "public class EntryPoint {",
            "  static void foo(int x) {}",
            "  public static void onModuleLoad() {",
            "    foo(123);",
            "  }",
            "}");

    checkOnModuleLoad(
        program,
        "function onModuleLoad(){"
            + "var stackIndex;$stack[stackIndex=++$stackDepth]=onModuleLoad;"
            + "$location[stackIndex]='EntryPoint.java:'+'4',$clinit_EntryPoint();"
            + "foo(($tmp=123,$location[stackIndex]='EntryPoint.java:'+'5',$tmp));"
            + "$stackDepth=stackIndex-1}");
  }