2
0
Эх сурвалжийг харах

[cs] unwrap TargetInvocationException
Fixes exceptions from static closures (closes #9957)

Aleksandr Kuzmenko 4 жил өмнө
parent
commit
f94d25f025

+ 12 - 3
std/cs/internal/Runtime.hx

@@ -475,17 +475,26 @@ import cs.system.Object;
 				tgs[i] = untyped __typeof__(Dynamic);
 				tgs[i] = untyped __typeof__(Dynamic);
 			}
 			}
 			m = m.MakeGenericMethod(tgs);
 			m = m.MakeGenericMethod(tgs);
-			var retg = m.Invoke(obj, oargs);
+			var retg = try
+				m.Invoke(obj, oargs)
+			catch(e:TargetInvocationException)
+				throw e.InnerException;
 			return cs.internal.Runtime.unbox(retg);
 			return cs.internal.Runtime.unbox(retg);
 		}
 		}
 
 
 		var m = methods[0];
 		var m = methods[0];
 		if (obj == null && Std.isOfType(m, cs.system.reflection.ConstructorInfo)) {
 		if (obj == null && Std.isOfType(m, cs.system.reflection.ConstructorInfo)) {
-			var ret = cast(m, cs.system.reflection.ConstructorInfo).Invoke(oargs);
+			var ret = try
+				cast(m, cs.system.reflection.ConstructorInfo).Invoke(oargs)
+			catch(e:TargetInvocationException)
+				throw e.InnerException;
 			return unbox(ret);
 			return unbox(ret);
 		}
 		}
 
 
-		var ret = m.Invoke(obj, oargs);
+		var ret = try
+			m.Invoke(obj, oargs)
+		catch(e:TargetInvocationException)
+			throw e.InnerException;
 		return unbox(ret);
 		return unbox(ret);
 	}
 	}
 
 

+ 2 - 2
tests/unit/src/unit/issues/Issue6871.hx

@@ -17,14 +17,14 @@ class Issue6871 extends unit.Test {
 			Reflect.getProperty(Issue6871, 'field');
 			Reflect.getProperty(Issue6871, 'field');
 			t(false);
 			t(false);
 		} catch(e:Dynamic) {
 		} catch(e:Dynamic) {
-			eq(GETTER_ERROR, exception(e));
+			eq(GETTER_ERROR, e);
 		}
 		}
 
 
 		try {
 		try {
 			Reflect.setProperty(Issue6871, 'field', 123);
 			Reflect.setProperty(Issue6871, 'field', 123);
 			t(false);
 			t(false);
 		} catch(e:Dynamic) {
 		} catch(e:Dynamic) {
-			eq(SETTER_ERROR, exception(e));
+			eq(SETTER_ERROR, e);
 		}
 		}
 	}
 	}
 }
 }

+ 32 - 0
tests/unit/src/unit/issues/Issue9957.hx

@@ -0,0 +1,32 @@
+package unit.issues;
+
+class Issue9957 extends unit.Test {
+	function test() {
+		var stat = staticExc;
+		var inst = instanceExc;
+
+		try {
+			try stat()
+			catch(_:MyEx) noAssert();
+		} catch(_) {
+			assert("Can't catch exceptions from static closures");
+		}
+
+		try {
+			try inst()
+			catch(_:MyEx) noAssert();
+		} catch(_) {
+			assert("Can't catch exceptions from instance closures");
+		}
+	}
+
+	static function staticExc() {
+		throw new MyEx('');
+	}
+
+	function instanceExc() {
+		throw new MyEx('');
+	}
+}
+
+private class MyEx extends haxe.Exception {}