コード例 #1
0
ファイル: JsStackEmulatorTest.java プロジェクト: linight/gwt
  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"
            + "}");
  }
コード例 #2
0
ファイル: JsStackEmulatorTest.java プロジェクト: linight/gwt
  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())"
            + "}");
  }
コード例 #3
0
ファイル: JsStackEmulatorTest.java プロジェクト: linight/gwt
  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)))"
            + "}");
  }
コード例 #4
0
ファイル: Recompiler.java プロジェクト: damocles33/gwt
 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;
 }
コード例 #5
0
ファイル: JsStackEmulatorTest.java プロジェクト: linight/gwt
  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}");
  }
コード例 #6
0
ファイル: JsStackEmulatorTest.java プロジェクト: linight/gwt
  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))"
            + "}");
  }
コード例 #7
0
ファイル: JsStackEmulatorTest.java プロジェクト: linight/gwt
  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}");
  }