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

Method RunSourceData

js/modules/resolution.go:265–293  ·  view source on GitHub ↗

RunSourceData runs the provided sourceData and adds it to the cache. If a module with the same specifier as the source is already cached it will be used instead of reevaluating the source from the provided SourceData.

(source *loader.SourceData)

Source from the content-addressed store, hash-verified

263// If a module with the same specifier as the source is already cached
264// it will be used instead of reevaluating the source from the provided SourceData.
265func (ms *ModuleSystem) RunSourceData(source *loader.SourceData) (*RunSourceDataResult, error) {
266 specifier := source.URL.String()
267 pwd := source.URL.JoinPath("../")
268 err := ms.resolver.LoadMainModule(pwd, specifier, source.Data)
269 if err != nil {
270 return nil, err
271 }
272 mod, err := ms.resolver.resolve(pwd, specifier)
273 if err != nil {
274 return nil, err
275 }
276 if err = mod.Link(); err != nil {
277 return nil, err
278 }
279 ci, ok := mod.(sobek.CyclicModuleRecord)
280 if !ok {
281 panic("somehow running source data for " + source.URL.String() + " didn't produce a cyclic module record")
282 }
283
284 rt := ms.vu.Runtime()
285 promise := rt.CyclicModuleRecordEvaluate(ci, ms.resolver.sobekModuleResolver)
286
287 promisesThenIgnore(rt, promise)
288
289 return &RunSourceDataResult{
290 promise: promise,
291 mod: mod,
292 }, nil
293}
294
295// RunSourceDataResult helps with the asynchronous nature of ESM
296// it wraps the promise that is returned from Sobek while at the same time allowing access to the module record

Callers 2

instantiateMethod · 0.95
runTC39ModuleMethod · 0.95

Calls 6

promisesThenIgnoreFunction · 0.85
LoadMainModuleMethod · 0.80
resolveMethod · 0.80
RuntimeMethod · 0.65
StringMethod · 0.45
LinkMethod · 0.45

Tested by 1

runTC39ModuleMethod · 0.76