|
@@ -1,55 +1,53 @@
|
|
using System.Threading;
|
|
using System.Threading;
|
|
using Jint.Constraints;
|
|
using Jint.Constraints;
|
|
|
|
|
|
-namespace Jint
|
|
|
|
|
|
+// ReSharper disable once CheckNamespace
|
|
|
|
+namespace Jint;
|
|
|
|
+
|
|
|
|
+public static class ConstraintsOptionsExtensions
|
|
{
|
|
{
|
|
- public static class ConstraintsOptionsExtensions
|
|
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// Limits the allowed statement count that can be run as part of the program.
|
|
|
|
+ /// </summary>
|
|
|
|
+ public static Options MaxStatements(this Options options, int maxStatements = 0)
|
|
{
|
|
{
|
|
- /// <summary>
|
|
|
|
- /// Limits the allowed statement count that can be run as part of the program.
|
|
|
|
- /// </summary>
|
|
|
|
- public static Options MaxStatements(this Options options, int maxStatements = 0)
|
|
|
|
- {
|
|
|
|
- options.WithoutConstraint(x => x is MaxStatements);
|
|
|
|
|
|
+ options.WithoutConstraint(x => x is MaxStatementsConstraint);
|
|
|
|
|
|
- if (maxStatements > 0 && maxStatements < int.MaxValue)
|
|
|
|
- {
|
|
|
|
- options.Constraint(new MaxStatements(maxStatements));
|
|
|
|
- }
|
|
|
|
- return options;
|
|
|
|
|
|
+ if (maxStatements > 0 && maxStatements < int.MaxValue)
|
|
|
|
+ {
|
|
|
|
+ options.Constraint(new MaxStatementsConstraint(maxStatements));
|
|
}
|
|
}
|
|
|
|
+ return options;
|
|
|
|
+ }
|
|
|
|
|
|
- public static Options LimitMemory(this Options options, long memoryLimit)
|
|
|
|
- {
|
|
|
|
- options.WithoutConstraint(x => x is MemoryLimit);
|
|
|
|
|
|
+ public static Options LimitMemory(this Options options, long memoryLimit)
|
|
|
|
+ {
|
|
|
|
+ options.WithoutConstraint(x => x is MemoryLimitConstraint);
|
|
|
|
|
|
- if (memoryLimit > 0 && memoryLimit < int.MaxValue)
|
|
|
|
- {
|
|
|
|
- options.Constraint(new MemoryLimit(memoryLimit));
|
|
|
|
- }
|
|
|
|
- return options;
|
|
|
|
|
|
+ if (memoryLimit > 0 && memoryLimit < int.MaxValue)
|
|
|
|
+ {
|
|
|
|
+ options.Constraint(new MemoryLimitConstraint(memoryLimit));
|
|
}
|
|
}
|
|
|
|
+ return options;
|
|
|
|
+ }
|
|
|
|
|
|
- public static Options TimeoutInterval(this Options options, TimeSpan timeoutInterval)
|
|
|
|
|
|
+ public static Options TimeoutInterval(this Options options, TimeSpan timeoutInterval)
|
|
|
|
+ {
|
|
|
|
+ if (timeoutInterval > TimeSpan.Zero && timeoutInterval < TimeSpan.MaxValue)
|
|
{
|
|
{
|
|
- options.WithoutConstraint(x => x is TimeConstraint);
|
|
|
|
-
|
|
|
|
- if (timeoutInterval > TimeSpan.Zero && timeoutInterval < TimeSpan.MaxValue)
|
|
|
|
- {
|
|
|
|
- options.Constraint(new TimeConstraint2(timeoutInterval));
|
|
|
|
- }
|
|
|
|
- return options;
|
|
|
|
|
|
+ options.Constraint(new TimeConstraint(timeoutInterval));
|
|
}
|
|
}
|
|
|
|
+ return options;
|
|
|
|
+ }
|
|
|
|
|
|
- public static Options CancellationToken(this Options options, CancellationToken cancellationToken)
|
|
|
|
- {
|
|
|
|
- options.WithoutConstraint(x => x is CancellationConstraint);
|
|
|
|
|
|
+ public static Options CancellationToken(this Options options, CancellationToken cancellationToken)
|
|
|
|
+ {
|
|
|
|
+ options.WithoutConstraint(x => x is CancellationConstraint);
|
|
|
|
|
|
- if (cancellationToken != default)
|
|
|
|
- {
|
|
|
|
- options.Constraint(new CancellationConstraint(cancellationToken));
|
|
|
|
- }
|
|
|
|
- return options;
|
|
|
|
|
|
+ if (cancellationToken != default)
|
|
|
|
+ {
|
|
|
|
+ options.Constraint(new CancellationConstraint(cancellationToken));
|
|
}
|
|
}
|
|
|
|
+ return options;
|
|
}
|
|
}
|
|
}
|
|
}
|