Engine.Helpers.cs 848 B

123456789101112131415161718192021222324252627282930313233
  1. using Jint.Runtime.Environments;
  2. namespace Jint;
  3. /// <summary>
  4. /// Contains helpers and compatibility shims.
  5. /// </summary>
  6. public partial class Engine
  7. {
  8. /// <summary>
  9. /// Creates a new declarative environment that has current lexical environment as outer scope.
  10. /// </summary>
  11. public EnvironmentRecord CreateNewDeclarativeEnvironment()
  12. {
  13. return JintEnvironment.NewDeclarativeEnvironment(this, ExecutionContext.LexicalEnvironment);
  14. }
  15. /// <summary>
  16. /// Return the first constraint that matches the predicate.
  17. /// </summary>
  18. public T? FindConstraint<T>() where T : Constraint
  19. {
  20. foreach (var constraint in _constraints)
  21. {
  22. if (constraint.GetType() == typeof(T))
  23. {
  24. return (T) constraint;
  25. }
  26. }
  27. return null;
  28. }
  29. }