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)
| 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. |
| 265 | func (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 |