Skip to content

Commit

Permalink
Update to work with ToObject instead of cast
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ankur22 committed Nov 14, 2024
1 parent 134399b commit 296f8c2
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions js/modules/gomodule.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 296f8c2

Please sign in to comment.