runCallable executes fn under timeout and returns the result. On error the raw VM error is logged and returned; the caller should wrap it with additional context (e.g. the function name) before surfacing to callers.
(vmw *VMWrapper, timeout time.Duration, fn goja.Callable, args ...goja.Value)
| 101 | // On error the raw VM error is logged and returned; the caller should wrap it |
| 102 | // with additional context (e.g. the function name) before surfacing to callers. |
| 103 | func runCallable(vmw *VMWrapper, timeout time.Duration, fn goja.Callable, args ...goja.Value) (goja.Value, error) { |
| 104 | tmr := time.AfterFunc(timeout, func() { |
| 105 | vmw.VM.Interrupt(errTimeout) |
| 106 | }) |
| 107 | res, err := fn(goja.Undefined(), args...) |
| 108 | vmw.VM.ClearInterrupt() |
| 109 | tmr.Stop() |
| 110 | if err != nil { |
| 111 | return nil, wrapVMError("call", err) |
| 112 | } |
| 113 | return res, nil |
| 114 | } |
no test coverage detected