From 264ba62fd82fb61f572b18ef106f63c947488ca6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Miri=C4=87?= Date: Fri, 13 Aug 2021 10:32:14 +0200 Subject: [PATCH] Avoid some common.Throw() usage Resolves https://github.com/grafana/xk6-execution/pull/2#discussion_r688299116 --- pkg/execution/execution.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/pkg/execution/execution.go b/pkg/execution/execution.go index 43a7d20..2df44af 100644 --- a/pkg/execution/execution.go +++ b/pkg/execution/execution.go @@ -63,7 +63,7 @@ func (*RootModule) NewModuleInstance(m modules.InstanceCore) modules.Instance { err := o.DefineAccessorProperty(name, rt.ToValue(func() goja.Value { obj, err := newInfo() if err != nil { - common.Throw(mi.GetRuntime(), err) + common.Throw(rt, err) } return obj }), nil, goja.FLAG_FALSE, goja.FLAG_TRUE) @@ -127,7 +127,7 @@ func (mi *ModuleInstance) newScenarioInfo() (*goja.Object, error) { }, } - return newInfoObj(rt, si), nil + return newInfoObj(rt, si) } // newTestInfo returns a goja.Object with property accessors to retrieve @@ -162,7 +162,7 @@ func (mi *ModuleInstance) newTestInfo() (*goja.Object, error) { }, } - return newInfoObj(rt, ti), nil + return newInfoObj(rt, ti) } // newVUInfo returns a goja.Object with property accessors to retrieve @@ -188,18 +188,18 @@ func (mi *ModuleInstance) newVUInfo() (*goja.Object, error) { }, } - return newInfoObj(rt, vi), nil + return newInfoObj(rt, vi) } -func newInfoObj(rt *goja.Runtime, props map[string]func() interface{}) *goja.Object { +func newInfoObj(rt *goja.Runtime, props map[string]func() interface{}) (*goja.Object, error) { o := rt.NewObject() for p, get := range props { err := o.DefineAccessorProperty(p, rt.ToValue(get), nil, goja.FLAG_FALSE, goja.FLAG_TRUE) if err != nil { - common.Throw(rt, err) + return nil, err } } - return o + return o, nil }