mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-07-26 06:38:42 +00:00
compiler: make map and channel panics recoverable
Change hashmap set operations and channel send/close from createRuntimeCall to createRuntimeInvoke. This places a setjmp checkpoint before each call, allowing runtimePanicAt to safely longjmp when these operations panic.
This commit is contained in:
Vendored
+20
@@ -41,6 +41,9 @@ func main() {
|
||||
|
||||
println("\n# recover runtime errors")
|
||||
recoverRuntimeError()
|
||||
|
||||
println("\n# recover from nil map and closed channel")
|
||||
recoverNilMapAndChan()
|
||||
}
|
||||
|
||||
func recoverSimple() {
|
||||
@@ -241,3 +244,20 @@ func recoverMustPanic(name string, f func()) {
|
||||
}()
|
||||
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
|
||||
})
|
||||
recoverMustPanic("closed chan", func() {
|
||||
ch := make(chan int)
|
||||
close(ch)
|
||||
ch <- 1
|
||||
})
|
||||
recoverMustPanic("close nil chan", func() {
|
||||
var ch chan int
|
||||
close(ch)
|
||||
})
|
||||
}
|
||||
|
||||
Vendored
+5
@@ -44,3 +44,8 @@ outer recovered: repanic value
|
||||
recovered: slice
|
||||
recovered: type assert
|
||||
recovered: empty interface type assert
|
||||
|
||||
# recover from nil map and closed channel
|
||||
recovered: nil map
|
||||
recovered: closed chan
|
||||
recovered: close nil chan
|
||||
|
||||
Reference in New Issue
Block a user