Options.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. using System.Globalization;
  2. using Jint.Runtime.Interop;
  3. namespace Jint
  4. {
  5. public class Options
  6. {
  7. private bool _discardGlobal;
  8. private bool _strict;
  9. private bool _allowDebuggerStatement;
  10. private bool _allowClr;
  11. private ITypeConverter _typeConverter = new DefaultTypeConverter();
  12. private int _maxStatements;
  13. private CultureInfo _culture = CultureInfo.CurrentCulture;
  14. /// <summary>
  15. /// When called, doesn't initialize the global scope.
  16. /// Can be useful in lightweight scripts for performance reason.
  17. /// </summary>
  18. public Options DiscardGlobal(bool discard = true)
  19. {
  20. _discardGlobal = discard;
  21. return this;
  22. }
  23. /// <summary>
  24. /// Run the script in strict mode.
  25. /// </summary>
  26. public Options Strict(bool strict = true)
  27. {
  28. _strict = strict;
  29. return this;
  30. }
  31. /// <summary>
  32. /// Allow the <code>debugger</code> statement to be called in a script.
  33. /// </summary>
  34. /// <remarks>
  35. /// Because the <code>debugger</code> statement can start the
  36. /// Visual Studio debugger, is it disabled by default
  37. /// </remarks>
  38. public Options AllowDebuggerStatement(bool allowDebuggerStatement = true)
  39. {
  40. _allowDebuggerStatement = allowDebuggerStatement;
  41. return this;
  42. }
  43. /// <summary>
  44. /// Sets a <see cref="ITypeConverter"/> instance to use when converting CLR types
  45. /// </summary>
  46. public Options SetTypeConverter(ITypeConverter typeConverter)
  47. {
  48. _typeConverter = typeConverter;
  49. return this;
  50. }
  51. public Options AllowClr(bool allowClr = true)
  52. {
  53. _allowClr = allowClr;
  54. return this;
  55. }
  56. public Options MaxStatements(int maxStatements = 0)
  57. {
  58. _maxStatements = maxStatements;
  59. return this;
  60. }
  61. public Options Culture(CultureInfo cultureInfo)
  62. {
  63. _culture = cultureInfo;
  64. return this;
  65. }
  66. internal bool GetDiscardGlobal()
  67. {
  68. return _discardGlobal;
  69. }
  70. internal bool IsStrict()
  71. {
  72. return _strict;
  73. }
  74. internal bool IsDebuggerStatementAllowed()
  75. {
  76. return _allowDebuggerStatement;
  77. }
  78. internal bool IsClrAllowed()
  79. {
  80. return _allowClr;
  81. }
  82. internal ITypeConverter GetTypeConverter()
  83. {
  84. return _typeConverter;
  85. }
  86. internal int GetMaxStatements()
  87. {
  88. return _maxStatements;
  89. }
  90. internal CultureInfo GetCulture()
  91. {
  92. return _culture;
  93. }
  94. }
  95. }