FailFastModuleLoader.cs 941 B

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