| 186 | } |
| 187 | |
| 188 | func (j jsInstance) runScript(pg *goja.Program) (res any, err error) { |
| 189 | defer func(res *any, err *error) { |
| 190 | if panicReason := recover(); panicReason != nil { |
| 191 | *res = nil |
| 192 | switch panicReason := panicReason.(type) { |
| 193 | case string: |
| 194 | *err = fmt.Errorf("panic: %s", panicReason) |
| 195 | case error: |
| 196 | *err = panicReason |
| 197 | default: |
| 198 | *err = fmt.Errorf("panic occurred: failed to retrieve panic information. Expected string or error, got %T", panicReason) |
| 199 | } |
| 200 | } |
| 201 | }(&res, &err) |
| 202 | res, err = j.rt.RunProgram(pg) |
| 203 | return res, err |
| 204 | } |