mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-09-14 16:32:59 +00:00
runtime: avoid heap allocs for plain errors
This commit is contained in:
Vendored
+17
@@ -313,12 +313,29 @@ func recoverMustPanic(name string, f func()) {
|
||||
f()
|
||||
}
|
||||
|
||||
func recoverRuntimeErrorValue(f func()) {
|
||||
defer func() {
|
||||
r := recover()
|
||||
err, ok := r.(runtime.Error)
|
||||
if ok {
|
||||
println(" recovered runtime error:", err.Error())
|
||||
} else {
|
||||
println(" failed runtime error:", r)
|
||||
}
|
||||
}()
|
||||
f()
|
||||
}
|
||||
|
||||
// Test recovering from nil map assignment and closed channel send.
|
||||
func recoverNilMapAndChan() {
|
||||
recoverMustPanic("nil map", func() {
|
||||
var m map[string]int
|
||||
m["x"] = 1
|
||||
})
|
||||
recoverRuntimeErrorValue(func() {
|
||||
var m map[string]int
|
||||
m["x"] = 1
|
||||
})
|
||||
recoverMustPanic("closed chan", func() {
|
||||
ch := make(chan int)
|
||||
close(ch)
|
||||
|
||||
Reference in New Issue
Block a user