From 00febd97c9f1495dae1fd03df64915ca6e4fa914 Mon Sep 17 00:00:00 2001 From: Mihail Stoykov Date: Mon, 14 Oct 2024 18:42:48 +0300 Subject: [PATCH] WIP to work around #3983 --- js/eventloop/eventloop.go | 11 ++++++++++- vendor/github.com/grafana/sobek/builtin_promise.go | 5 ++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/js/eventloop/eventloop.go b/js/eventloop/eventloop.go index 038326c80ba..3a6ab6efc65 100644 --- a/js/eventloop/eventloop.go +++ b/js/eventloop/eventloop.go @@ -124,7 +124,16 @@ func (e *EventLoop) RegisterCallback() (enqueueCallback func(func() error)) { panic("RegisterCallback called twice") } callbackCalled = true - e.queue = append(e.queue, f) + wrapFunc := func() error { + rt := e.vu.Runtime() + callable, _ := sobek.AssertFunction(rt.ToValue(f)) + _, err := callable(nil) + // if there is an exception the err will be nil either way + + return err + } + + e.queue = append(e.queue, wrapFunc) e.registeredCallbacks-- e.lock.Unlock() e.wakeup() diff --git a/vendor/github.com/grafana/sobek/builtin_promise.go b/vendor/github.com/grafana/sobek/builtin_promise.go index a4a1255a141..8cb71537d80 100644 --- a/vendor/github.com/grafana/sobek/builtin_promise.go +++ b/vendor/github.com/grafana/sobek/builtin_promise.go @@ -598,7 +598,10 @@ func (r *Runtime) getPromise() *Object { func (r *Runtime) wrapPromiseReaction(fObj *Object) func(interface{}) { f, _ := AssertFunction(fObj) return func(x interface{}) { - _, _ = f(nil, r.ToValue(x)) + _, err := f(nil, r.ToValue(x)) + if err != nil { + panic(err) + } } }