MCPcopy
hub / github.com/grafana/k6 / getModuleInstanceFromGoModule

Method getModuleInstanceFromGoModule

js/modules/require_impl.go:70–97  ·  view source on GitHub ↗
(wm *goModule)

Source from the content-addressed store, hash-verified

68}
69
70func (ms *ModuleSystem) getModuleInstanceFromGoModule(wm *goModule) (wmi *goModuleInstance, err error) {
71 rt := ms.vu.Runtime()
72 mi := rt.GetModuleInstance(wm)
73 if mi == nil {
74 err = wm.Link()
75 if err != nil {
76 return nil, err
77 }
78 promise := rt.CyclicModuleRecordEvaluate(wm, ms.resolver.sobekModuleResolver)
79 switch promise.State() {
80 case sobek.PromiseStateRejected:
81 err = promise.Result().Export().(error) //nolint:forcetypeassert
82 case sobek.PromiseStateFulfilled:
83 default:
84 panic("TLA in go modules is not supported in k6 at the moment")
85 }
86 if err != nil {
87 return nil, err
88 }
89 mi = rt.GetModuleInstance(wm)
90 }
91 gmi, ok := mi.(*goModuleInstance)
92 if !ok {
93 panic(fmt.Sprintf("a goModule instance is of not goModuleInstance type (got %T). "+
94 "This is a k6 bug please report it (https://github.com/grafana/k6/issues)", mi))
95 }
96 return gmi, nil
97}
98
99// Resolve returns what the provided specifier will get resolved to if it was to be imported
100// To be used by other parts to get the path

Callers 2

RequireMethod · 0.95
ExportGloballyModuleFunction · 0.80

Calls 5

ExportMethod · 0.80
ResultMethod · 0.80
RuntimeMethod · 0.65
StateMethod · 0.65
LinkMethod · 0.45

Tested by

no test coverage detected