FailFastModuleLoader.cs 1003 B

1234567891011121314151617181920212223242526272829303132333435
  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. #pragma warning disable CA1822
  7. public Uri BasePath
  8. #pragma warning restore CA1822
  9. {
  10. get
  11. {
  12. ExceptionHelper.ThrowInvalidOperationException("Cannot access base path when modules loading is disabled");
  13. return default;
  14. }
  15. }
  16. public ResolvedSpecifier Resolve(string? referencingModuleLocation, string specifier)
  17. {
  18. return new ResolvedSpecifier(specifier, specifier, null, SpecifierType.Bare);
  19. }
  20. public Module LoadModule(Engine engine, ResolvedSpecifier resolved)
  21. {
  22. ThrowDisabledException();
  23. return default!;
  24. }
  25. private static void ThrowDisabledException()
  26. {
  27. ExceptionHelper.ThrowInvalidOperationException("Module loading has been disabled, you need to enable it in engine options");
  28. }
  29. }