[Runtime] Add a function pointer for intercepting swift_willThrow calls.

rdar://problem/53400364
This commit is contained in:
Mike Ash
2019-10-22 15:50:14 -04:00
parent c55965519e
commit b8f5e841e2
9 changed files with 135 additions and 46 deletions

View File

@@ -191,5 +191,23 @@ ErrorTests.test("test dealloc empty error box") {
}
}
var errors: [Error] = []
ErrorTests.test("willThrow") {
typealias WillThrow = @convention(c) (Error) -> Void
let willThrow = pointerToSwiftCoreSymbol(name: "_swift_willThrow")!
willThrow.storeBytes(of: { errors.append($0) }, as: WillThrow.self)
expectTrue(errors.isEmpty)
do {
throw UnsignedError.negativeOne
} catch {}
expectEqual(UnsignedError.self, type(of: errors.last!))
do {
throw SillyError.JazzHands
} catch {}
expectEqual(2, errors.count)
expectEqual(SillyError.self, type(of: errors.last!))
}
runAllTests()