Browse Source

Restructure and internalize (#1738)

* Move Reference to Jint.Runtime namespace
* Internalize Binding
* Internalize Advanced operations constructors
* Make Advanced operations inner classes
* Make Options sub-options inner classes
* Move delegate definitions under options
* Make StrictModeScope internal
* Move ModuleBuilder under Runtime.Modules namespace
Marko Lahma 1 year ago
parent
commit
a1788187de
30 changed files with 304 additions and 323 deletions
  1. 0 1
      Jint.Tests/Runtime/NullPropagation.cs
  2. 47 47
      Jint/Engine.Advanced.cs
  3. 33 33
      Jint/Engine.Constraints.cs
  4. 11 12
      Jint/Engine.Modules.cs
  5. 0 1
      Jint/Engine.cs
  6. 1 1
      Jint/Native/Json/JsonParser.cs
  7. 3 3
      Jint/Options.Extensions.cs
  8. 194 193
      Jint/Options.cs
  9. 1 2
      Jint/Pooling/ArgumentsInstancePool.cs
  10. 1 1
      Jint/Pooling/ReferencePool.cs
  11. 0 1
      Jint/Runtime/DefaultReferenceResolver.cs
  12. 1 1
      Jint/Runtime/Environments/Binding.cs
  13. 0 1
      Jint/Runtime/ExceptionHelper.cs
  14. 1 1
      Jint/Runtime/Interop/ClrFunction.cs
  15. 2 2
      Jint/Runtime/Interop/ClrHelper.cs
  16. 0 1
      Jint/Runtime/Interop/IReferenceResolver.cs
  17. 2 2
      Jint/Runtime/Interop/TypeResolver.cs
  18. 0 1
      Jint/Runtime/Interpreter/Expressions/BindingPatternAssignmentExpression.cs
  19. 0 1
      Jint/Runtime/Interpreter/Expressions/JintAssignmentExpression.cs
  20. 0 1
      Jint/Runtime/Interpreter/Expressions/JintCallExpression.cs
  21. 0 1
      Jint/Runtime/Interpreter/Expressions/JintExpression.cs
  22. 0 1
      Jint/Runtime/Interpreter/Expressions/JintMemberExpression.cs
  23. 0 1
      Jint/Runtime/Interpreter/Expressions/JintTaggedTemplateExpression.cs
  24. 0 1
      Jint/Runtime/Interpreter/Expressions/JintUnaryExpression.cs
  25. 0 1
      Jint/Runtime/Interpreter/Expressions/JintUpdateExpression.cs
  26. 0 1
      Jint/Runtime/Interpreter/Statements/JintForInForOfStatement.cs
  27. 0 1
      Jint/Runtime/Interpreter/Statements/JintVariableDeclaration.cs
  28. 5 8
      Jint/Runtime/Modules/ModuleBuilder.cs
  29. 1 1
      Jint/Runtime/Reference.cs
  30. 1 1
      Jint/StrictModeScope.cs

+ 0 - 1
Jint.Tests/Runtime/NullPropagation.cs

@@ -1,7 +1,6 @@
 using Jint.Native;
 using Jint.Runtime;
 using Jint.Runtime.Interop;
-using Jint.Runtime.References;
 
 namespace Jint.Tests.Runtime
 {

+ 47 - 47
Jint/Engine.Advanced.cs

@@ -5,62 +5,62 @@ namespace Jint;
 public partial class Engine
 {
     public AdvancedOperations Advanced { get; }
-}
-
-public class AdvancedOperations
-{
-    private readonly Engine _engine;
 
-    public AdvancedOperations(Engine engine)
+    public class AdvancedOperations
     {
-        _engine = engine;
-    }
+        private readonly Engine _engine;
 
-    /// <summary>
-    /// Gets current stack trace that is active in engine.
-    /// </summary>
-    public string StackTrace
-    {
-        get
+        internal AdvancedOperations(Engine engine)
         {
-            var lastSyntaxElement = _engine._lastSyntaxElement;
-            if (lastSyntaxElement is null)
+            _engine = engine;
+        }
+
+        /// <summary>
+        /// Gets current stack trace that is active in engine.
+        /// </summary>
+        public string StackTrace
+        {
+            get
             {
-                return string.Empty;
-            }
+                var lastSyntaxElement = _engine._lastSyntaxElement;
+                if (lastSyntaxElement is null)
+                {
+                    return string.Empty;
+                }
 
-            return _engine.CallStack.BuildCallStackString(lastSyntaxElement.Location);
+                return _engine.CallStack.BuildCallStackString(lastSyntaxElement.Location);
+            }
         }
-    }
 
-    /// <summary>
-    /// Initializes list of references of called functions
-    /// </summary>
-    public void ResetCallStack()
-    {
-        _engine.ResetCallStack();
-    }
+        /// <summary>
+        /// Initializes list of references of called functions
+        /// </summary>
+        public void ResetCallStack()
+        {
+            _engine.ResetCallStack();
+        }
 
-    /// <summary>
-    /// Forcefully processes the current task queues (micro and regular), this API may break and change behavior!
-    /// </summary>
-    public void ProcessTasks()
-    {
-        _engine.RunAvailableContinuations();
-    }
+        /// <summary>
+        /// Forcefully processes the current task queues (micro and regular), this API may break and change behavior!
+        /// </summary>
+        public void ProcessTasks()
+        {
+            _engine.RunAvailableContinuations();
+        }
 
-    /// <summary>
-    /// EXPERIMENTAL! Subject to change.
-    ///
-    /// Registers a promise within the currently running EventLoop (has to be called within "ExecuteWithEventLoop" call).
-    /// Note that ExecuteWithEventLoop will not trigger "onFinished" callback until ALL manual promises are settled.
-    ///
-    /// NOTE: that resolve and reject need to be called withing the same thread as "ExecuteWithEventLoop".
-    /// The API assumes that the Engine is called from a single thread.
-    /// </summary>
-    /// <returns>a Promise instance and functions to either resolve or reject it</returns>
-    public ManualPromise RegisterPromise()
-    {
-        return _engine.RegisterPromise();
+        /// <summary>
+        /// EXPERIMENTAL! Subject to change.
+        ///
+        /// Registers a promise within the currently running EventLoop (has to be called within "ExecuteWithEventLoop" call).
+        /// Note that ExecuteWithEventLoop will not trigger "onFinished" callback until ALL manual promises are settled.
+        ///
+        /// NOTE: that resolve and reject need to be called withing the same thread as "ExecuteWithEventLoop".
+        /// The API assumes that the Engine is called from a single thread.
+        /// </summary>
+        /// <returns>a Promise instance and functions to either resolve or reject it</returns>
+        public ManualPromise RegisterPromise()
+        {
+            return _engine.RegisterPromise();
+        }
     }
 }

+ 33 - 33
Jint/Engine.Constraints.cs

@@ -3,52 +3,52 @@ namespace Jint;
 public partial class Engine
 {
     public ConstraintOperations Constraints { get; }
-}
-
-public class ConstraintOperations
-{
-    private readonly Engine _engine;
 
-    public ConstraintOperations(Engine engine)
+    public class ConstraintOperations
     {
-        _engine = engine;
-    }
+        private readonly Engine _engine;
 
-    /// <summary>
-    /// Checks engine's active constraints. Propagates exceptions from constraints.
-    /// </summary>
-    public void Check()
-    {
-        foreach (var constraint in _engine._constraints)
+        internal ConstraintOperations(Engine engine)
         {
-            constraint.Check();
+            _engine = engine;
         }
-    }
 
-    /// <summary>
-    /// Return the first constraint that matches the predicate.
-    /// </summary>
-    public T? Find<T>() where T : Constraint
-    {
-        foreach (var constraint in _engine._constraints)
+        /// <summary>
+        /// Checks engine's active constraints. Propagates exceptions from constraints.
+        /// </summary>
+        public void Check()
         {
-            if (constraint.GetType() == typeof(T))
+            foreach (var constraint in _engine._constraints)
             {
-                return (T) constraint;
+                constraint.Check();
             }
         }
 
-        return null;
-    }
+        /// <summary>
+        /// Return the first constraint that matches the predicate.
+        /// </summary>
+        public T? Find<T>() where T : Constraint
+        {
+            foreach (var constraint in _engine._constraints)
+            {
+                if (constraint.GetType() == typeof(T))
+                {
+                    return (T) constraint;
+                }
+            }
 
-    /// <summary>
-    /// Resets all execution constraints back to their initial state.
-    /// </summary>
-    public void Reset()
-    {
-        foreach (var constraint in _engine._constraints)
+            return null;
+        }
+
+        /// <summary>
+        /// Resets all execution constraints back to their initial state.
+        /// </summary>
+        public void Reset()
         {
-            constraint.Reset();
+            foreach (var constraint in _engine._constraints)
+            {
+                constraint.Reset();
+            }
         }
     }
 }

+ 11 - 12
Jint/Engine.Modules.cs

@@ -6,19 +6,18 @@ using Jint.Runtime;
 using Jint.Runtime.Interpreter;
 using Jint.Runtime.Modules;
 
-namespace Jint
+namespace Jint;
+
+public partial class Engine
 {
-    public partial class Engine
-    {
-        public ModuleOperations Modules { get; internal set; } = null!;
+    public ModuleOperations Modules { get; internal set; } = null!;
 
-        /// <summary>
-        /// https://tc39.es/ecma262/#sec-getactivescriptormodule
-        /// </summary>
-        internal IScriptOrModule? GetActiveScriptOrModule()
-        {
-            return _executionContexts?.GetActiveScriptOrModule();
-        }
+    /// <summary>
+    /// https://tc39.es/ecma262/#sec-getactivescriptormodule
+    /// </summary>
+    internal IScriptOrModule? GetActiveScriptOrModule()
+    {
+        return _executionContexts?.GetActiveScriptOrModule();
     }
 
     public class ModuleOperations
@@ -56,7 +55,7 @@ namespace Jint
 
             if (module is SourceTextModule sourceTextModule)
             {
-               _engine.Debugger.OnBeforeEvaluate(sourceTextModule._source);
+                _engine.Debugger.OnBeforeEvaluate(sourceTextModule._source);
             }
 
             return module;

+ 0 - 1
Jint/Engine.cs

@@ -19,7 +19,6 @@ using Jint.Runtime.Interop;
 using Jint.Runtime.Interop.Reflection;
 using Jint.Runtime.Interpreter;
 using Jint.Runtime.Interpreter.Expressions;
-using Jint.Runtime.References;
 using Environment = Jint.Runtime.Environments.Environment;
 
 namespace Jint

+ 1 - 1
Jint/Native/Json/JsonParser.cs

@@ -15,7 +15,7 @@ namespace Jint.Native.Json
         private readonly int _maxDepth;
 
         /// <summary>
-        /// Creates a new parser using the recursion depth specified in <see cref="JsonOptions.MaxParseDepth"/>.
+        /// Creates a new parser using the recursion depth specified in <see cref="Options.JsonOptions.MaxParseDepth"/>.
         /// </summary>
         public JsonParser(Engine engine)
             : this(engine, engine.Options.Json.MaxParseDepth)

+ 3 - 3
Jint/Options.Extensions.cs

@@ -121,7 +121,7 @@ namespace Jint
         /// ObjectInstance using class ObjectWrapper. This function can be used to
         /// register a handler for a customized handling.
         /// </summary>
-        public static Options SetWrapObjectHandler(this Options options, WrapObjectDelegate wrapObjectHandler)
+        public static Options SetWrapObjectHandler(this Options options, Options.WrapObjectDelegate wrapObjectHandler)
         {
             options.Interop.WrapObjectHandler = wrapObjectHandler;
             return options;
@@ -146,7 +146,7 @@ namespace Jint
         /// The delegate to invoke for each CLR member. If the delegate
         /// returns <c>null</c>, the standard evaluation is performed.
         /// </param>
-        public static Options SetMemberAccessor(this Options options, MemberAccessorDelegate accessor)
+        public static Options SetMemberAccessor(this Options options, Options.MemberAccessorDelegate accessor)
         {
             options.Interop.MemberAccessor = accessor;
             return options;
@@ -191,7 +191,7 @@ namespace Jint
         /// can be used in at try/catch statement. By default these exceptions are bubbled
         /// to the CLR host and interrupt the script execution.
         /// </summary>
-        public static Options CatchClrExceptions(this Options options, ExceptionHandlerDelegate handler)
+        public static Options CatchClrExceptions(this Options options, Options.ExceptionHandlerDelegate handler)
         {
             options.Interop.ExceptionHandler = handler;
             return options;

+ 194 - 193
Jint/Options.cs

@@ -13,12 +13,6 @@ using Jint.Runtime.CallStack;
 
 namespace Jint
 {
-    public delegate JsValue? MemberAccessorDelegate(Engine engine, object target, string member);
-
-    public delegate ObjectInstance? WrapObjectDelegate(Engine engine, object target, Type? type);
-
-    public delegate bool ExceptionHandlerDelegate(Exception exception);
-
     public class Options
     {
         private static readonly CultureInfo _defaultCulture = CultureInfo.CurrentCulture;
@@ -27,6 +21,12 @@ namespace Jint
         private ITimeSystem? _timeSystem;
         internal List<Action<Engine>> _configurations { get; } = new();
 
+        public delegate JsValue? MemberAccessorDelegate(Engine engine, object target, string member);
+
+        public delegate ObjectInstance? WrapObjectDelegate(Engine engine, object target, Type? type);
+
+        public delegate bool ExceptionHandlerDelegate(Exception exception);
+
         /// <summary>
         /// Execution constraints for the engine.
         /// </summary>
@@ -146,7 +146,7 @@ namespace Jint
                     PropertyFlag.AllForbidden));
             }
 
-            engine.Modules = new ModuleOperations(engine, Modules.ModuleLoader);
+            engine.Modules = new Engine.ModuleOperations(engine, Modules.ModuleLoader);
         }
 
         private static void AttachExtensionMethodsToPrototypes(Engine engine)
@@ -217,136 +217,206 @@ namespace Jint
                 }
             }
         }
-    }
-
-    public class DebuggerOptions
-    {
-        /// <summary>
-        /// Whether debugger functionality is enabled, defaults to false.
-        /// </summary>
-        public bool Enabled { get; set; }
-
-        /// <summary>
-        /// Configures the statement handling strategy, defaults to Ignore.
-        /// </summary>
-        public DebuggerStatementHandling StatementHandling { get; set; } = DebuggerStatementHandling.Ignore;
-
-        /// <summary>
-        /// Configures the step mode used when entering the script.
-        /// </summary>
-        public StepMode InitialStepMode { get; set; } = StepMode.None;
-    }
-
-    public class InteropOptions
-    {
-        /// <summary>
-        /// Whether accessing CLR and it's types and methods is allowed from JS code, defaults to false.
-        /// </summary>
-        public bool Enabled { get; set; }
-
-        /// <summary>
-        /// Whether to expose <see cref="object.GetType"></see> which can allow bypassing allow lists and open a way to reflection.
-        /// Defaults to false.
-        /// </summary>
-        public bool AllowGetType { get; set; }
-
-        /// <summary>
-        /// Whether Jint should allow wrapping objects from System.Reflection namespace.
-        /// Defaults to false.
-        /// </summary>
-        public bool AllowSystemReflection { get; set; }
-
-        /// <summary>
-        /// Whether writing to CLR objects is allowed (set properties), defaults to true.
-        /// </summary>
-        public bool AllowWrite { get; set; } = true;
-
-        /// <summary>
-        /// Whether operator overloading resolution is allowed, defaults to false.
-        /// </summary>
-        public bool AllowOperatorOverloading { get; set; }
 
-        /// <summary>
-        /// Types holding extension methods that should be considered when resolving methods.
-        /// </summary>
-        public List<Type> ExtensionMethodTypes { get; } = new();
 
-        /// <summary>
-        /// Object converters to try when build-in conversions.
-        /// </summary>
-        public List<IObjectConverter> ObjectConverters { get; } = new();
-
-        /// <summary>
-        /// Whether identity map is persisted for object wrappers in order to maintain object identity. This can cause
-        /// memory usage to grow when targeting large set and freeing of memory can be delayed due to ConditionalWeakTable semantics.
-        /// Defaults to false.
-        /// </summary>
-        public bool TrackObjectWrapperIdentity { get; set; }
-
-        /// <summary>
-        /// If no known type could be guessed, objects are by default wrapped as an
-        /// ObjectInstance using class ObjectWrapper. This function can be used to
-        /// change the behavior.
-        /// </summary>
-        public WrapObjectDelegate WrapObjectHandler { get; set; } = static (engine, target, type) => new ObjectWrapper(engine, target, type);
-
-        /// <summary>
-        ///
-        /// </summary>
-        public MemberAccessorDelegate MemberAccessor { get; set; } = static (engine, target, member) => null;
-
-        /// <summary>
-        /// Exceptions that thrown from CLR code are converted to JavaScript errors and
-        /// can be used in at try/catch statement. By default these exceptions are bubbled
-        /// to the CLR host and interrupt the script execution. If handler returns true these exceptions are converted
-        /// to JS errors that can be caught by the script.
-        /// </summary>
-        public ExceptionHandlerDelegate ExceptionHandler { get; set; } = _defaultExceptionHandler;
-
-        /// <summary>
-        /// Assemblies to allow scripts to call CLR types directly like <example>System.IO.File</example>.
-        /// </summary>
-        public List<Assembly> AllowedAssemblies { get; set; } = new();
-
-        /// <summary>
-        /// Type and member resolving strategy, which allows filtering allowed members and configuring member
-        /// name matching comparison.
-        /// </summary>
-        /// <remarks>
-        /// As this object holds caching state same instance should be shared between engines, if possible.
-        /// </remarks>
-        public TypeResolver TypeResolver { get; set; } = TypeResolver.Default;
+        public class DebuggerOptions
+        {
+            /// <summary>
+            /// Whether debugger functionality is enabled, defaults to false.
+            /// </summary>
+            public bool Enabled { get; set; }
+
+            /// <summary>
+            /// Configures the statement handling strategy, defaults to Ignore.
+            /// </summary>
+            public DebuggerStatementHandling StatementHandling { get; set; } = DebuggerStatementHandling.Ignore;
+
+            /// <summary>
+            /// Configures the step mode used when entering the script.
+            /// </summary>
+            public StepMode InitialStepMode { get; set; } = StepMode.None;
+        }
 
-        /// <summary>
-        /// When writing values to CLR objects, how should JS values be coerced to CLR types.
-        /// Defaults to only coercing to string values when writing to string targets.
-        /// </summary>
-        public ValueCoercionType ValueCoercion { get; set; } = ValueCoercionType.String;
+        public class InteropOptions
+        {
+            /// <summary>
+            /// Whether accessing CLR and it's types and methods is allowed from JS code, defaults to false.
+            /// </summary>
+            public bool Enabled { get; set; }
+
+            /// <summary>
+            /// Whether to expose <see cref="object.GetType"></see> which can allow bypassing allow lists and open a way to reflection.
+            /// Defaults to false.
+            /// </summary>
+            public bool AllowGetType { get; set; }
+
+            /// <summary>
+            /// Whether Jint should allow wrapping objects from System.Reflection namespace.
+            /// Defaults to false.
+            /// </summary>
+            public bool AllowSystemReflection { get; set; }
+
+            /// <summary>
+            /// Whether writing to CLR objects is allowed (set properties), defaults to true.
+            /// </summary>
+            public bool AllowWrite { get; set; } = true;
+
+            /// <summary>
+            /// Whether operator overloading resolution is allowed, defaults to false.
+            /// </summary>
+            public bool AllowOperatorOverloading { get; set; }
+
+            /// <summary>
+            /// Types holding extension methods that should be considered when resolving methods.
+            /// </summary>
+            public List<Type> ExtensionMethodTypes { get; } = new();
+
+            /// <summary>
+            /// Object converters to try when build-in conversions.
+            /// </summary>
+            public List<IObjectConverter> ObjectConverters { get; } = new();
+
+            /// <summary>
+            /// Whether identity map is persisted for object wrappers in order to maintain object identity. This can cause
+            /// memory usage to grow when targeting large set and freeing of memory can be delayed due to ConditionalWeakTable semantics.
+            /// Defaults to false.
+            /// </summary>
+            public bool TrackObjectWrapperIdentity { get; set; }
+
+            /// <summary>
+            /// If no known type could be guessed, objects are by default wrapped as an
+            /// ObjectInstance using class ObjectWrapper. This function can be used to
+            /// change the behavior.
+            /// </summary>
+            public WrapObjectDelegate WrapObjectHandler { get; set; } = static (engine, target, type) => new ObjectWrapper(engine, target, type);
+
+            /// <summary>
+            ///
+            /// </summary>
+            public MemberAccessorDelegate MemberAccessor { get; set; } = static (engine, target, member) => null;
+
+            /// <summary>
+            /// Exceptions that thrown from CLR code are converted to JavaScript errors and
+            /// can be used in at try/catch statement. By default these exceptions are bubbled
+            /// to the CLR host and interrupt the script execution. If handler returns true these exceptions are converted
+            /// to JS errors that can be caught by the script.
+            /// </summary>
+            public ExceptionHandlerDelegate ExceptionHandler { get; set; } = _defaultExceptionHandler;
+
+            /// <summary>
+            /// Assemblies to allow scripts to call CLR types directly like <example>System.IO.File</example>.
+            /// </summary>
+            public List<Assembly> AllowedAssemblies { get; set; } = new();
+
+            /// <summary>
+            /// Type and member resolving strategy, which allows filtering allowed members and configuring member
+            /// name matching comparison.
+            /// </summary>
+            /// <remarks>
+            /// As this object holds caching state same instance should be shared between engines, if possible.
+            /// </remarks>
+            public TypeResolver TypeResolver { get; set; } = TypeResolver.Default;
+
+            /// <summary>
+            /// When writing values to CLR objects, how should JS values be coerced to CLR types.
+            /// Defaults to only coercing to string values when writing to string targets.
+            /// </summary>
+            public ValueCoercionType ValueCoercion { get; set; } = ValueCoercionType.String;
+
+            /// <summary>
+            /// Strategy to create a CLR object to hold converted <see cref="ObjectInstance"/>.
+            /// </summary>
+            public Func<ObjectInstance, IDictionary<string, object?>>? CreateClrObject = _ => new ExpandoObject();
+
+            /// <summary>
+            /// Strategy to create a CLR object from TypeReference.
+            /// Defaults to retuning null which makes TypeReference attempt to find suitable constructor.
+            /// </summary>
+            public Func<Engine, Type, JsValue[], object?> CreateTypeReferenceObject = (_, _, _) => null;
+
+            internal static readonly ExceptionHandlerDelegate _defaultExceptionHandler = static exception => false;
+
+            /// <summary>
+            /// When not null, is used to serialize any CLR object in an
+            /// <see cref="IObjectWrapper"/> passing through 'JSON.stringify'.
+            /// </summary>
+            public Func<object, string>? SerializeToJson { get; set; }
+
+            /// <summary>
+            /// What kind of date time should be produced when JavaScript date is converted to DateTime. If Local, uses <see cref="Options.TimeZone"/>.
+            /// Defaults to <see cref="System.DateTimeKind.Utc"/>.
+            /// </summary>
+            public DateTimeKind DateTimeKind { get; set; } = DateTimeKind.Utc;
+        }
 
-        /// <summary>
-        /// Strategy to create a CLR object to hold converted <see cref="ObjectInstance"/>.
-        /// </summary>
-        public Func<ObjectInstance, IDictionary<string, object?>>? CreateClrObject = _ => new ExpandoObject();
+        public class ConstraintOptions
+        {
+            /// <summary>
+            /// Registered constraints.
+            /// </summary>
+            public List<Constraint> Constraints { get; } = new();
+
+            /// <summary>
+            /// Maximum recursion depth allowed, defaults to -1 (no checks).
+            /// </summary>
+            public int MaxRecursionDepth { get; set; } = -1;
+
+            /// <summary>
+            /// Maximum recursion stack count, defaults to -1 (as-is dotnet stacktrace).
+            /// </summary>
+            /// <remarks>
+            /// Chrome and V8 based engines (ClearScript) that can handle 13955.
+            /// When set to a different value except -1, it can reduce slight performance/stack trace readability drawback. (after hitting the engine's own limit),
+            /// When max stack size to be exceeded, Engine throws an exception <see cref="JavaScriptException" />.
+            /// </remarks>
+            public int MaxExecutionStackCount { get; set; } = StackGuard.Disabled;
+
+            /// <summary>
+            /// Maximum time a Regex is allowed to run, defaults to 10 seconds.
+            /// </summary>
+            public TimeSpan RegexTimeout { get; set; } = TimeSpan.FromSeconds(10);
+
+            /// <summary>
+            /// The maximum size for JavaScript array, defaults to <see cref="uint.MaxValue"/>.
+            /// </summary>
+            public uint MaxArraySize { get; set; } = uint.MaxValue;
+        }
 
         /// <summary>
-        /// Strategy to create a CLR object from TypeReference.
-        /// Defaults to retuning null which makes TypeReference attempt to find suitable constructor.
+        /// Host related customization, still work in progress.
         /// </summary>
-        public Func<Engine, Type, JsValue[], object?> CreateTypeReferenceObject = (_, _, _) => null;
-
-        internal static readonly ExceptionHandlerDelegate _defaultExceptionHandler = static exception => false;
+        public class HostOptions
+        {
+            internal Func<Engine, Host> Factory { get; set; } = _ => new Host();
+        }
 
         /// <summary>
-        /// When not null, is used to serialize any CLR object in an
-        /// <see cref="IObjectWrapper"/> passing through 'JSON.stringify'.
+        /// Module related customization
         /// </summary>
-        public Func<object, string>? SerializeToJson { get; set; }
+        public class ModuleOptions
+        {
+            /// <summary>
+            /// Whether to register require function to engine which will delegate to module loader, defaults to false.
+            /// </summary>
+            public bool RegisterRequire { get; set; }
+
+            /// <summary>
+            /// Module loader implementation, by default exception will be thrown if module loading is not enabled.
+            /// </summary>
+            public IModuleLoader ModuleLoader { get; set; } = FailFastModuleLoader.Instance;
+        }
 
         /// <summary>
-        /// What kind of date time should be produced when JavaScript date is converted to DateTime. If Local, uses <see cref="Options.TimeZone"/>.
-        /// Defaults to <see cref="System.DateTimeKind.Utc"/>.
+        /// JSON.parse / JSON.stringify related customization
         /// </summary>
-        public DateTimeKind DateTimeKind { get; set; } = DateTimeKind.Utc;
+        public class JsonOptions
+        {
+            /// <summary>
+            /// The maximum depth allowed when parsing JSON files using "JSON.parse",
+            /// defaults to 64.
+            /// </summary>
+            public int MaxParseDepth { get; set; } = 64;
+        }
     }
 
     /// <summary>
@@ -381,73 +451,4 @@ namespace Jint
         /// </summary>
         All = Boolean | Number | String
     }
-
-    public class ConstraintOptions
-    {
-        /// <summary>
-        /// Registered constraints.
-        /// </summary>
-        public List<Constraint> Constraints { get; } = new();
-
-        /// <summary>
-        /// Maximum recursion depth allowed, defaults to -1 (no checks).
-        /// </summary>
-        public int MaxRecursionDepth { get; set; } = -1;
-
-        /// <summary>
-        /// Maximum recursion stack count, defaults to -1 (as-is dotnet stacktrace).
-        /// </summary>
-        /// <remarks>
-        /// Chrome and V8 based engines (ClearScript) that can handle 13955.
-        /// When set to a different value except -1, it can reduce slight performance/stack trace readability drawback. (after hitting the engine's own limit),
-        /// When max stack size to be exceeded, Engine throws an exception <see cref="JavaScriptException" />.
-        /// </remarks>
-        public int MaxExecutionStackCount { get; set; } = StackGuard.Disabled;
-
-        /// <summary>
-        /// Maximum time a Regex is allowed to run, defaults to 10 seconds.
-        /// </summary>
-        public TimeSpan RegexTimeout { get; set; } = TimeSpan.FromSeconds(10);
-
-        /// <summary>
-        /// The maximum size for JavaScript array, defaults to <see cref="uint.MaxValue"/>.
-        /// </summary>
-        public uint MaxArraySize { get; set; } = uint.MaxValue;
-    }
-
-    /// <summary>
-    /// Host related customization, still work in progress.
-    /// </summary>
-    public class HostOptions
-    {
-        internal Func<Engine, Host> Factory { get; set; } = _ => new Host();
-    }
-
-    /// <summary>
-    /// Module related customization
-    /// </summary>
-    public class ModuleOptions
-    {
-        /// <summary>
-        /// Whether to register require function to engine which will delegate to module loader, defaults to false.
-        /// </summary>
-        public bool RegisterRequire { get; set; }
-
-        /// <summary>
-        /// Module loader implementation, by default exception will be thrown if module loading is not enabled.
-        /// </summary>
-        public IModuleLoader ModuleLoader { get; set; } = FailFastModuleLoader.Instance;
-    }
-
-    /// <summary>
-    /// JSON.parse / JSON.stringify related customization
-    /// </summary>
-    public class JsonOptions
-    {
-        /// <summary>
-        /// The maximum depth allowed when parsing JSON files using "JSON.parse",
-        /// defaults to 64.
-        /// </summary>
-        public int MaxParseDepth { get; set; } = 64;
-    }
 }

+ 1 - 2
Jint/Pooling/ArgumentsInstancePool.cs

@@ -2,12 +2,11 @@ using Jint.Native;
 using Jint.Native.Argument;
 using Jint.Native.Function;
 using Jint.Runtime.Environments;
-using Jint.Runtime.References;
 
 namespace Jint.Pooling
 {
     /// <summary>
-    /// Cache reusable <see cref="Reference" /> instances as we allocate them a lot.
+    /// Cache reusable <see cref="JsArguments" /> instances as we allocate them a lot.
     /// </summary>
     internal sealed class ArgumentsInstancePool
     {

+ 1 - 1
Jint/Pooling/ReferencePool.cs

@@ -1,5 +1,5 @@
 using Jint.Native;
-using Jint.Runtime.References;
+using Jint.Runtime;
 
 namespace Jint.Pooling
 {

+ 0 - 1
Jint/Runtime/DefaultReferenceResolver.cs

@@ -1,6 +1,5 @@
 using Jint.Native;
 using Jint.Runtime.Interop;
-using Jint.Runtime.References;
 
 namespace Jint.Runtime
 {

+ 1 - 1
Jint/Runtime/Environments/Binding.cs

@@ -4,7 +4,7 @@ using Jint.Native;
 namespace Jint.Runtime.Environments
 {
     [DebuggerDisplay("Mutable: {Mutable}, Strict: {Strict}, CanBeDeleted: {CanBeDeleted}, Value: {Value}")]
-    public readonly struct Binding
+    internal readonly struct Binding
     {
         public Binding(
             JsValue value,

+ 0 - 1
Jint/Runtime/ExceptionHelper.cs

@@ -7,7 +7,6 @@ using Jint.Native;
 using Jint.Native.Error;
 using Jint.Runtime.CallStack;
 using Jint.Runtime.Modules;
-using Jint.Runtime.References;
 
 namespace Jint.Runtime
 {

+ 1 - 1
Jint/Runtime/Interop/ClrFunction.cs

@@ -30,7 +30,7 @@ public sealed class ClrFunction : Function, IEquatable<ClrFunction>
             ? PropertyDescriptor.AllForbiddenDescriptor.ForNumber(length)
             : new PropertyDescriptor(JsNumber.Create(length), lengthFlags);
 
-        _bubbleExceptions = _engine.Options.Interop.ExceptionHandler == InteropOptions._defaultExceptionHandler;
+        _bubbleExceptions = _engine.Options.Interop.ExceptionHandler == Options.InteropOptions._defaultExceptionHandler;
     }
 
     protected internal override JsValue Call(JsValue thisObject, JsValue[] arguments) => _bubbleExceptions ? _func(thisObject, arguments) : CallSlow(thisObject, arguments);

+ 2 - 2
Jint/Runtime/Interop/ClrHelper.cs

@@ -4,9 +4,9 @@ using Jint.Native;
 
 public class ClrHelper
 {
-    private readonly InteropOptions _interopOptions;
+    private readonly Options.InteropOptions _interopOptions;
 
-    internal ClrHelper(InteropOptions interopOptions)
+    internal ClrHelper(Options.InteropOptions interopOptions)
     {
         _interopOptions = interopOptions;
     }

+ 0 - 1
Jint/Runtime/Interop/IReferenceResolver.cs

@@ -1,5 +1,4 @@
 using Jint.Native;
-using Jint.Runtime.References;
 
 namespace Jint.Runtime.Interop
 {

+ 2 - 2
Jint/Runtime/Interop/TypeResolver.cs

@@ -16,9 +16,9 @@ namespace Jint.Runtime.Interop
 
         /// <summary>
         /// Registers a filter that determines whether given member is wrapped to interop or returned as undefined.
-        /// By default allows all but will also be limited by <see cref="InteropOptions.AllowGetType"/> configuration.
+        /// By default allows all but will also be limited by <see cref="Options.InteropOptions.AllowGetType"/> configuration.
         /// </summary>
-        /// <seealso cref="InteropOptions.AllowGetType"/>
+        /// <seealso cref="Options.InteropOptions.AllowGetType"/>
         public Predicate<MemberInfo> MemberFilter { get; set; } = _ => true;
 
         internal bool Filter(Engine engine, MemberInfo m)

+ 0 - 1
Jint/Runtime/Interpreter/Expressions/BindingPatternAssignmentExpression.cs

@@ -3,7 +3,6 @@ using Jint.Native;
 using Jint.Native.Array;
 using Jint.Native.Function;
 using Jint.Native.Iterator;
-using Jint.Runtime.References;
 using Environment = Jint.Runtime.Environments.Environment;
 
 namespace Jint.Runtime.Interpreter.Expressions

+ 0 - 1
Jint/Runtime/Interpreter/Expressions/JintAssignmentExpression.cs

@@ -3,7 +3,6 @@ using Esprima.Ast;
 using Jint.Native;
 using Jint.Native.Function;
 using Jint.Runtime.Environments;
-using Jint.Runtime.References;
 using Environment = Jint.Runtime.Environments.Environment;
 
 namespace Jint.Runtime.Interpreter.Expressions

+ 0 - 1
Jint/Runtime/Interpreter/Expressions/JintCallExpression.cs

@@ -6,7 +6,6 @@ using Jint.Native.Function;
 using Jint.Native.Object;
 using Jint.Runtime.CallStack;
 using Jint.Runtime.Environments;
-using Jint.Runtime.References;
 using Environment = Jint.Runtime.Environments.Environment;
 
 namespace Jint.Runtime.Interpreter.Expressions

+ 0 - 1
Jint/Runtime/Interpreter/Expressions/JintExpression.cs

@@ -4,7 +4,6 @@ using Esprima.Ast;
 using Jint.Native;
 using Jint.Native.Iterator;
 using Jint.Native.Number;
-using Jint.Runtime.References;
 
 namespace Jint.Runtime.Interpreter.Expressions
 {

+ 0 - 1
Jint/Runtime/Interpreter/Expressions/JintMemberExpression.cs

@@ -1,7 +1,6 @@
 using Esprima.Ast;
 using Jint.Native;
 using Jint.Runtime.Environments;
-using Jint.Runtime.References;
 
 namespace Jint.Runtime.Interpreter.Expressions
 {

+ 0 - 1
Jint/Runtime/Interpreter/Expressions/JintTaggedTemplateExpression.cs

@@ -2,7 +2,6 @@ using Esprima.Ast;
 using Jint.Native;
 using Jint.Native.Object;
 using Jint.Runtime.Descriptors;
-using Jint.Runtime.References;
 
 namespace Jint.Runtime.Interpreter.Expressions;
 

+ 0 - 1
Jint/Runtime/Interpreter/Expressions/JintUnaryExpression.cs

@@ -2,7 +2,6 @@ using Esprima.Ast;
 using Jint.Extensions;
 using Jint.Native;
 using Jint.Runtime.Interop;
-using Jint.Runtime.References;
 using System.Collections.Concurrent;
 using System.Diagnostics.CodeAnalysis;
 using System.Numerics;

+ 0 - 1
Jint/Runtime/Interpreter/Expressions/JintUpdateExpression.cs

@@ -1,7 +1,6 @@
 using Esprima.Ast;
 using Jint.Native;
 using Jint.Runtime.Environments;
-using Jint.Runtime.References;
 
 namespace Jint.Runtime.Interpreter.Expressions
 {

+ 0 - 1
Jint/Runtime/Interpreter/Statements/JintForInForOfStatement.cs

@@ -4,7 +4,6 @@ using Jint.Native;
 using Jint.Native.Iterator;
 using Jint.Runtime.Environments;
 using Jint.Runtime.Interpreter.Expressions;
-using Jint.Runtime.References;
 using Environment = Jint.Runtime.Environments.Environment;
 
 namespace Jint.Runtime.Interpreter.Statements

+ 0 - 1
Jint/Runtime/Interpreter/Statements/JintVariableDeclaration.cs

@@ -2,7 +2,6 @@ using Esprima.Ast;
 using Jint.Native;
 using Jint.Native.Function;
 using Jint.Runtime.Interpreter.Expressions;
-using Jint.Runtime.References;
 
 namespace Jint.Runtime.Interpreter.Statements
 {

+ 5 - 8
Jint/ModuleBuilder.cs → Jint/Runtime/Modules/ModuleBuilder.cs

@@ -1,18 +1,15 @@
 using Esprima;
 using Esprima.Ast;
 using Jint.Native;
-using Jint.Runtime;
 using Jint.Runtime.Interop;
-using Jint.Runtime.Modules;
-using Module = Esprima.Ast.Module;
 
-namespace Jint;
+namespace Jint.Runtime.Modules;
 
 public sealed class ModuleBuilder
 {
     private readonly Engine _engine;
     private readonly string _specifier;
-    private Module? _module;
+    private global::Esprima.Ast.Module? _module;
     private readonly List<string> _sourceRaw = new();
     private readonly Dictionary<string, JsValue> _exports = new(StringComparer.Ordinal);
     private readonly ParserOptions _options;
@@ -37,7 +34,7 @@ public sealed class ModuleBuilder
         return this;
     }
 
-    public ModuleBuilder AddModule(Module module)
+    public ModuleBuilder AddModule(global::Esprima.Ast.Module module)
     {
         if (_sourceRaw.Count > 0)
         {
@@ -126,12 +123,12 @@ public sealed class ModuleBuilder
         return this;
     }
 
-    internal Module Parse()
+    internal global::Esprima.Ast.Module Parse()
     {
         if (_module != null) return _module;
         if (_sourceRaw.Count <= 0)
         {
-            return new Module(NodeList.Create(Array.Empty<Statement>()));
+            return new global::Esprima.Ast.Module(NodeList.Create(Array.Empty<Statement>()));
         }
 
         var javaScriptParser = new JavaScriptParser(_options);

+ 1 - 1
Jint/Runtime/References/Reference.cs → Jint/Runtime/Reference.cs

@@ -4,7 +4,7 @@ using Jint.Native;
 using Jint.Runtime.Environments;
 using Environment = Jint.Runtime.Environments.Environment;
 
-namespace Jint.Runtime.References;
+namespace Jint.Runtime;
 
 /// <summary>
 /// https://tc39.es/ecma262/#sec-reference-record-specification-type

+ 1 - 1
Jint/StrictModeScope.cs

@@ -3,7 +3,7 @@ using System.Runtime.InteropServices;
 namespace Jint
 {
     [StructLayout(LayoutKind.Auto)]
-    public readonly struct StrictModeScope : IDisposable
+    internal readonly struct StrictModeScope : IDisposable
     {
         private readonly bool _strict;
         private readonly bool _force;