浏览代码

[java] correctly set callstack

Cauê Waneck 11 年之前
父节点
当前提交
a2f9d7a838
共有 2 个文件被更改,包括 16 次插入6 次删除
  1. 8 1
      genjava.ml
  2. 8 5
      std/java/internal/Exceptions.hx

+ 8 - 1
genjava.ml

@@ -2064,7 +2064,14 @@ let configure gen =
 			)
 			(base_exception_t)
 			(hx_exception_t)
-			(fun v e -> e)
+			(fun v e ->
+
+				let exc_cl = get_cl (get_type gen (["haxe";"lang"],"Exceptions")) in
+				let exc_field = mk_static_field_access_infer exc_cl "setException" e.epos [] in
+				let esetstack = { eexpr = TCall(exc_field,[mk_local v e.epos]); etype = gen.gcon.basic.tvoid; epos = e.epos } in
+
+				Type.concat esetstack e;
+			)
 	);
 
 	let get_typeof e =

+ 8 - 5
std/java/internal/Exceptions.hx

@@ -24,13 +24,17 @@ import java.lang.Throwable;
 import java.lang.RuntimeException;
 import java.lang.Exception;
 
-@:allow(haxe.CallStack)
-@:allow(java.lang.RuntimeException)
 @:native("haxe.lang.Exceptions")
 class Exceptions {
-	private static var exception = new java.lang.ThreadLocal<java.lang.RuntimeException>();
+	private static var exception = new java.lang.ThreadLocal<java.lang.Throwable>();
 
-	private static function currentException() {
+	@:keep private static function setException(exc:Throwable)
+	{
+		exception.set(exc);
+	}
+
+	public static function currentException()
+	{
 		return exception.get();
 	}
 }
@@ -73,7 +77,6 @@ class Exceptions {
 			ret = new HaxeException(obj, null, obj);
 		else
 			ret = new HaxeException(obj, null, null);
-		Exceptions.exception.set( ret );
 		return ret;
 	}
 }