diff --git a/pkg/app/promise_proxy.go b/pkg/app/promise_proxy.go index dfdb4b4..094df4d 100644 --- a/pkg/app/promise_proxy.go +++ b/pkg/app/promise_proxy.go @@ -46,11 +46,11 @@ func NewPromiseProxyFrom(rt *goja.Runtime) *PromiseProxy { return NewPromiseProxy(promise, resolve, reject) } -func IsPromise(v goja.Value) (*goja.Promise, bool) { +func isPromise(v any) (*goja.Promise, bool) { if v == nil { return nil, false } - promise, ok := v.Export().(*goja.Promise) + promise, ok := v.(*goja.Promise) return promise, ok } diff --git a/pkg/app/server.go b/pkg/app/server.go index f14cf0b..4f40f8c 100644 --- a/pkg/app/server.go +++ b/pkg/app/server.go @@ -23,7 +23,7 @@ type Server struct { modules []ServerModule } -func (s *Server) ExecFuncByName(ctx context.Context, funcName string, args ...interface{}) (any, error) { +func (s *Server) ExecFuncByName(ctx context.Context, funcName string, args ...any) (any, error) { ctx = logger.With(ctx, logger.F("function", funcName), logger.F("args", args)) ret, err := s.Exec(ctx, funcName, args...) @@ -34,9 +34,9 @@ func (s *Server) ExecFuncByName(ctx context.Context, funcName string, args ...in return ret, nil } -func (s *Server) Exec(ctx context.Context, callableOrFuncname any, args ...interface{}) (any, error) { +func (s *Server) Exec(ctx context.Context, callableOrFuncname any, args ...any) (any, error) { type result struct { - value goja.Value + value any err error } @@ -110,7 +110,7 @@ func (s *Server) Exec(ctx context.Context, callableOrFuncname any, args ...inter } done <- result{ - value: value, + value: value.Export(), } logger.Debug(ctx, "executed callable", logger.F("callable", callableOrFuncname), logger.F("duration", time.Since(start).String())) @@ -129,13 +129,11 @@ func (s *Server) Exec(ctx context.Context, callableOrFuncname any, args ...inter return nil, errors.WithStack(result.err) } - value := result.value - - if promise, ok := IsPromise(value); ok { + if promise, ok := isPromise(result.value); ok { return s.waitForPromise(promise), nil } - return value.Export(), nil + return result.value, nil } }