From 296f8c286baa940621685b0a606536b955fc3792 Mon Sep 17 00:00:00 2001 From: ankur22 Date: Thu, 14 Nov 2024 11:59:09 +0000 Subject: [PATCH] Update to work with ToObject instead of cast This is a better and safer way to work with an interface{} type when we need to retrieve the property values from the object. Since the underlying type of Default could be anything, including a sobek.Value, it's better to retrieve it as a sobek.Object instead of a casting. --- js/modules/gomodule.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/js/modules/gomodule.go b/js/modules/gomodule.go index 7c8f5e1401a..14fda88b1ac 100644 --- a/js/modules/gomodule.go +++ b/js/modules/gomodule.go @@ -31,9 +31,8 @@ func (gm *goModule) Instantiate(rt *sobek.Runtime) (sobek.CyclicModuleInstance, // default and extract the names of the object's properties. This // behavior isn't ESM compatible, but we do want to allow defaults to // be imported as namespaced object, which is also how node works. - if obj, ok := mi.Exports().Default.(*sobek.Object); ok { - gm.exportedNames = obj.GetOwnPropertyNames() - } + obj := rt.ToValue(mi.Exports().Default).ToObject(rt) + gm.exportedNames = obj.GetOwnPropertyNames() default: gm.exportedNames = make([]string, 0, len(named)) for name := range named {