FailFastModuleLoader.cs 972 B

123456789101112131415161718192021222324252627282930313233343536
  1. #nullable enable
  2. using System;
  3. using Esprima.Ast;
  4. namespace Jint.Runtime.Modules;
  5. internal sealed class FailFastModuleLoader : IModuleLoader
  6. {
  7. public static readonly IModuleLoader Instance = new FailFastModuleLoader();
  8. public Uri BasePath
  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. }