FailFastModuleLoader.cs 987 B

123456789101112131415161718192021222324252627282930313233
  1. namespace Jint.Runtime.Modules;
  2. internal sealed class FailFastModuleLoader : IModuleLoader
  3. {
  4. public static readonly IModuleLoader Instance = new FailFastModuleLoader();
  5. #pragma warning disable CA1822
  6. public Uri BasePath
  7. #pragma warning restore CA1822
  8. {
  9. get
  10. {
  11. Throw.InvalidOperationException("Cannot access base path when modules loading is disabled");
  12. return default;
  13. }
  14. }
  15. public ResolvedSpecifier Resolve(string? referencingModuleLocation, ModuleRequest moduleRequest)
  16. {
  17. return new ResolvedSpecifier(moduleRequest, moduleRequest.Specifier, Uri: null, SpecifierType.Bare);
  18. }
  19. public Module LoadModule(Engine engine, ResolvedSpecifier resolved)
  20. {
  21. ThrowDisabledException();
  22. return default!;
  23. }
  24. private static void ThrowDisabledException()
  25. {
  26. Throw.InvalidOperationException("Module loading has been disabled, you need to enable it in engine options");
  27. }
  28. }