diff --git a/Jint.Tests/Runtime/NullPropagation.cs b/Jint.Tests/Runtime/NullPropagation.cs index cd78410393..e84e3b36c6 100644 --- a/Jint.Tests/Runtime/NullPropagation.cs +++ b/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 { diff --git a/Jint/Engine.Advanced.cs b/Jint/Engine.Advanced.cs index 873e085712..61b8672a0d 100644 --- a/Jint/Engine.Advanced.cs +++ b/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; - /// - /// Gets current stack trace that is active in engine. - /// - public string StackTrace - { - get + internal AdvancedOperations(Engine engine) { - var lastSyntaxElement = _engine._lastSyntaxElement; - if (lastSyntaxElement is null) + _engine = engine; + } + + /// + /// Gets current stack trace that is active in engine. + /// + 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); + } } - } - /// - /// Initializes list of references of called functions - /// - public void ResetCallStack() - { - _engine.ResetCallStack(); - } + /// + /// Initializes list of references of called functions + /// + public void ResetCallStack() + { + _engine.ResetCallStack(); + } - /// - /// Forcefully processes the current task queues (micro and regular), this API may break and change behavior! - /// - public void ProcessTasks() - { - _engine.RunAvailableContinuations(); - } + /// + /// Forcefully processes the current task queues (micro and regular), this API may break and change behavior! + /// + public void ProcessTasks() + { + _engine.RunAvailableContinuations(); + } - /// - /// 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. - /// - /// a Promise instance and functions to either resolve or reject it - public ManualPromise RegisterPromise() - { - return _engine.RegisterPromise(); + /// + /// 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. + /// + /// a Promise instance and functions to either resolve or reject it + public ManualPromise RegisterPromise() + { + return _engine.RegisterPromise(); + } } } diff --git a/Jint/Engine.Constraints.cs b/Jint/Engine.Constraints.cs index c8005ec3cb..47df6eb2c4 100644 --- a/Jint/Engine.Constraints.cs +++ b/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; - /// - /// Checks engine's active constraints. Propagates exceptions from constraints. - /// - public void Check() - { - foreach (var constraint in _engine._constraints) + internal ConstraintOperations(Engine engine) { - constraint.Check(); + _engine = engine; } - } - /// - /// Return the first constraint that matches the predicate. - /// - public T? Find() where T : Constraint - { - foreach (var constraint in _engine._constraints) + /// + /// Checks engine's active constraints. Propagates exceptions from constraints. + /// + public void Check() { - if (constraint.GetType() == typeof(T)) + foreach (var constraint in _engine._constraints) { - return (T) constraint; + constraint.Check(); } } - return null; - } + /// + /// Return the first constraint that matches the predicate. + /// + public T? Find() where T : Constraint + { + foreach (var constraint in _engine._constraints) + { + if (constraint.GetType() == typeof(T)) + { + return (T) constraint; + } + } - /// - /// Resets all execution constraints back to their initial state. - /// - public void Reset() - { - foreach (var constraint in _engine._constraints) + return null; + } + + /// + /// Resets all execution constraints back to their initial state. + /// + public void Reset() { - constraint.Reset(); + foreach (var constraint in _engine._constraints) + { + constraint.Reset(); + } } } } diff --git a/Jint/Engine.Modules.cs b/Jint/Engine.Modules.cs index 54f155aace..6b2e12ab9d 100644 --- a/Jint/Engine.Modules.cs +++ b/Jint/Engine.Modules.cs @@ -6,19 +6,18 @@ 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!; - /// - /// https://tc39.es/ecma262/#sec-getactivescriptormodule - /// - internal IScriptOrModule? GetActiveScriptOrModule() - { - return _executionContexts?.GetActiveScriptOrModule(); - } + /// + /// https://tc39.es/ecma262/#sec-getactivescriptormodule + /// + internal IScriptOrModule? GetActiveScriptOrModule() + { + return _executionContexts?.GetActiveScriptOrModule(); } public class ModuleOperations @@ -56,7 +55,7 @@ internal Module Load(string? referencingModuleLocation, ModuleRequest request) if (module is SourceTextModule sourceTextModule) { - _engine.Debugger.OnBeforeEvaluate(sourceTextModule._source); + _engine.Debugger.OnBeforeEvaluate(sourceTextModule._source); } return module; diff --git a/Jint/Engine.cs b/Jint/Engine.cs index 1484d192f3..f378baf9c2 100644 --- a/Jint/Engine.cs +++ b/Jint/Engine.cs @@ -19,7 +19,6 @@ 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 diff --git a/Jint/Native/Json/JsonParser.cs b/Jint/Native/Json/JsonParser.cs index 82925ba028..db38adb8b5 100644 --- a/Jint/Native/Json/JsonParser.cs +++ b/Jint/Native/Json/JsonParser.cs @@ -15,7 +15,7 @@ public sealed class JsonParser private readonly int _maxDepth; /// - /// Creates a new parser using the recursion depth specified in . + /// Creates a new parser using the recursion depth specified in . /// public JsonParser(Engine engine) : this(engine, engine.Options.Json.MaxParseDepth) diff --git a/Jint/Options.Extensions.cs b/Jint/Options.Extensions.cs index 38c50753ac..86822dcae0 100644 --- a/Jint/Options.Extensions.cs +++ b/Jint/Options.Extensions.cs @@ -121,7 +121,7 @@ public static Options AddExtensionMethods(this Options options, params Type[] ty /// ObjectInstance using class ObjectWrapper. This function can be used to /// register a handler for a customized handling. /// - 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 @@ public static Options SetTypeConverter(this Options options, Funcnull, the standard evaluation is performed. /// - 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 @@ public static Options CatchClrExceptions(this Options options) /// can be used in at try/catch statement. By default these exceptions are bubbled /// to the CLR host and interrupt the script execution. /// - 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; diff --git a/Jint/Options.cs b/Jint/Options.cs index f340c1acf6..a38ed7b8f0 100644 --- a/Jint/Options.cs +++ b/Jint/Options.cs @@ -13,12 +13,6 @@ 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 @@ public class Options private ITimeSystem? _timeSystem; internal List> _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); + /// /// Execution constraints for the engine. /// @@ -146,7 +146,7 @@ internal void Apply(Engine engine) 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 @@ PropertyDescriptor CreateMethodInstancePropertyDescriptor(ClrFunction? function) } } } - } - - public class DebuggerOptions - { - /// - /// Whether debugger functionality is enabled, defaults to false. - /// - public bool Enabled { get; set; } - - /// - /// Configures the statement handling strategy, defaults to Ignore. - /// - public DebuggerStatementHandling StatementHandling { get; set; } = DebuggerStatementHandling.Ignore; - - /// - /// Configures the step mode used when entering the script. - /// - public StepMode InitialStepMode { get; set; } = StepMode.None; - } - - public class InteropOptions - { - /// - /// Whether accessing CLR and it's types and methods is allowed from JS code, defaults to false. - /// - public bool Enabled { get; set; } - - /// - /// Whether to expose which can allow bypassing allow lists and open a way to reflection. - /// Defaults to false. - /// - public bool AllowGetType { get; set; } - - /// - /// Whether Jint should allow wrapping objects from System.Reflection namespace. - /// Defaults to false. - /// - public bool AllowSystemReflection { get; set; } - - /// - /// Whether writing to CLR objects is allowed (set properties), defaults to true. - /// - public bool AllowWrite { get; set; } = true; - - /// - /// Whether operator overloading resolution is allowed, defaults to false. - /// - public bool AllowOperatorOverloading { get; set; } - /// - /// Types holding extension methods that should be considered when resolving methods. - /// - public List ExtensionMethodTypes { get; } = new(); - /// - /// Object converters to try when build-in conversions. - /// - public List ObjectConverters { get; } = new(); - - /// - /// 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. - /// - public bool TrackObjectWrapperIdentity { get; set; } - - /// - /// 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. - /// - public WrapObjectDelegate WrapObjectHandler { get; set; } = static (engine, target, type) => new ObjectWrapper(engine, target, type); - - /// - /// - /// - public MemberAccessorDelegate MemberAccessor { get; set; } = static (engine, target, member) => null; - - /// - /// 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. - /// - public ExceptionHandlerDelegate ExceptionHandler { get; set; } = _defaultExceptionHandler; - - /// - /// Assemblies to allow scripts to call CLR types directly like System.IO.File. - /// - public List AllowedAssemblies { get; set; } = new(); - - /// - /// Type and member resolving strategy, which allows filtering allowed members and configuring member - /// name matching comparison. - /// - /// - /// As this object holds caching state same instance should be shared between engines, if possible. - /// - public TypeResolver TypeResolver { get; set; } = TypeResolver.Default; + public class DebuggerOptions + { + /// + /// Whether debugger functionality is enabled, defaults to false. + /// + public bool Enabled { get; set; } + + /// + /// Configures the statement handling strategy, defaults to Ignore. + /// + public DebuggerStatementHandling StatementHandling { get; set; } = DebuggerStatementHandling.Ignore; + + /// + /// Configures the step mode used when entering the script. + /// + public StepMode InitialStepMode { get; set; } = StepMode.None; + } - /// - /// 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. - /// - public ValueCoercionType ValueCoercion { get; set; } = ValueCoercionType.String; + public class InteropOptions + { + /// + /// Whether accessing CLR and it's types and methods is allowed from JS code, defaults to false. + /// + public bool Enabled { get; set; } + + /// + /// Whether to expose which can allow bypassing allow lists and open a way to reflection. + /// Defaults to false. + /// + public bool AllowGetType { get; set; } + + /// + /// Whether Jint should allow wrapping objects from System.Reflection namespace. + /// Defaults to false. + /// + public bool AllowSystemReflection { get; set; } + + /// + /// Whether writing to CLR objects is allowed (set properties), defaults to true. + /// + public bool AllowWrite { get; set; } = true; + + /// + /// Whether operator overloading resolution is allowed, defaults to false. + /// + public bool AllowOperatorOverloading { get; set; } + + /// + /// Types holding extension methods that should be considered when resolving methods. + /// + public List ExtensionMethodTypes { get; } = new(); + + /// + /// Object converters to try when build-in conversions. + /// + public List ObjectConverters { get; } = new(); + + /// + /// 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. + /// + public bool TrackObjectWrapperIdentity { get; set; } + + /// + /// 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. + /// + public WrapObjectDelegate WrapObjectHandler { get; set; } = static (engine, target, type) => new ObjectWrapper(engine, target, type); + + /// + /// + /// + public MemberAccessorDelegate MemberAccessor { get; set; } = static (engine, target, member) => null; + + /// + /// 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. + /// + public ExceptionHandlerDelegate ExceptionHandler { get; set; } = _defaultExceptionHandler; + + /// + /// Assemblies to allow scripts to call CLR types directly like System.IO.File. + /// + public List AllowedAssemblies { get; set; } = new(); + + /// + /// Type and member resolving strategy, which allows filtering allowed members and configuring member + /// name matching comparison. + /// + /// + /// As this object holds caching state same instance should be shared between engines, if possible. + /// + public TypeResolver TypeResolver { get; set; } = TypeResolver.Default; + + /// + /// 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. + /// + public ValueCoercionType ValueCoercion { get; set; } = ValueCoercionType.String; + + /// + /// Strategy to create a CLR object to hold converted . + /// + public Func>? CreateClrObject = _ => new ExpandoObject(); + + /// + /// Strategy to create a CLR object from TypeReference. + /// Defaults to retuning null which makes TypeReference attempt to find suitable constructor. + /// + public Func CreateTypeReferenceObject = (_, _, _) => null; + + internal static readonly ExceptionHandlerDelegate _defaultExceptionHandler = static exception => false; + + /// + /// When not null, is used to serialize any CLR object in an + /// passing through 'JSON.stringify'. + /// + public Func? SerializeToJson { get; set; } + + /// + /// What kind of date time should be produced when JavaScript date is converted to DateTime. If Local, uses . + /// Defaults to . + /// + public DateTimeKind DateTimeKind { get; set; } = DateTimeKind.Utc; + } - /// - /// Strategy to create a CLR object to hold converted . - /// - public Func>? CreateClrObject = _ => new ExpandoObject(); + public class ConstraintOptions + { + /// + /// Registered constraints. + /// + public List Constraints { get; } = new(); + + /// + /// Maximum recursion depth allowed, defaults to -1 (no checks). + /// + public int MaxRecursionDepth { get; set; } = -1; + + /// + /// Maximum recursion stack count, defaults to -1 (as-is dotnet stacktrace). + /// + /// + /// 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 . + /// + public int MaxExecutionStackCount { get; set; } = StackGuard.Disabled; + + /// + /// Maximum time a Regex is allowed to run, defaults to 10 seconds. + /// + public TimeSpan RegexTimeout { get; set; } = TimeSpan.FromSeconds(10); + + /// + /// The maximum size for JavaScript array, defaults to . + /// + public uint MaxArraySize { get; set; } = uint.MaxValue; + } /// - /// 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. /// - public Func CreateTypeReferenceObject = (_, _, _) => null; - - internal static readonly ExceptionHandlerDelegate _defaultExceptionHandler = static exception => false; + public class HostOptions + { + internal Func Factory { get; set; } = _ => new Host(); + } /// - /// When not null, is used to serialize any CLR object in an - /// passing through 'JSON.stringify'. + /// Module related customization /// - public Func? SerializeToJson { get; set; } + public class ModuleOptions + { + /// + /// Whether to register require function to engine which will delegate to module loader, defaults to false. + /// + public bool RegisterRequire { get; set; } + + /// + /// Module loader implementation, by default exception will be thrown if module loading is not enabled. + /// + public IModuleLoader ModuleLoader { get; set; } = FailFastModuleLoader.Instance; + } /// - /// What kind of date time should be produced when JavaScript date is converted to DateTime. If Local, uses . - /// Defaults to . + /// JSON.parse / JSON.stringify related customization /// - public DateTimeKind DateTimeKind { get; set; } = DateTimeKind.Utc; + public class JsonOptions + { + /// + /// The maximum depth allowed when parsing JSON files using "JSON.parse", + /// defaults to 64. + /// + public int MaxParseDepth { get; set; } = 64; + } } /// @@ -381,73 +451,4 @@ public enum ValueCoercionType /// All = Boolean | Number | String } - - public class ConstraintOptions - { - /// - /// Registered constraints. - /// - public List Constraints { get; } = new(); - - /// - /// Maximum recursion depth allowed, defaults to -1 (no checks). - /// - public int MaxRecursionDepth { get; set; } = -1; - - /// - /// Maximum recursion stack count, defaults to -1 (as-is dotnet stacktrace). - /// - /// - /// 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 . - /// - public int MaxExecutionStackCount { get; set; } = StackGuard.Disabled; - - /// - /// Maximum time a Regex is allowed to run, defaults to 10 seconds. - /// - public TimeSpan RegexTimeout { get; set; } = TimeSpan.FromSeconds(10); - - /// - /// The maximum size for JavaScript array, defaults to . - /// - public uint MaxArraySize { get; set; } = uint.MaxValue; - } - - /// - /// Host related customization, still work in progress. - /// - public class HostOptions - { - internal Func Factory { get; set; } = _ => new Host(); - } - - /// - /// Module related customization - /// - public class ModuleOptions - { - /// - /// Whether to register require function to engine which will delegate to module loader, defaults to false. - /// - public bool RegisterRequire { get; set; } - - /// - /// Module loader implementation, by default exception will be thrown if module loading is not enabled. - /// - public IModuleLoader ModuleLoader { get; set; } = FailFastModuleLoader.Instance; - } - - /// - /// JSON.parse / JSON.stringify related customization - /// - public class JsonOptions - { - /// - /// The maximum depth allowed when parsing JSON files using "JSON.parse", - /// defaults to 64. - /// - public int MaxParseDepth { get; set; } = 64; - } } diff --git a/Jint/Pooling/ArgumentsInstancePool.cs b/Jint/Pooling/ArgumentsInstancePool.cs index 5ddd51a09a..f70d001497 100644 --- a/Jint/Pooling/ArgumentsInstancePool.cs +++ b/Jint/Pooling/ArgumentsInstancePool.cs @@ -2,12 +2,11 @@ using Jint.Native.Argument; using Jint.Native.Function; using Jint.Runtime.Environments; -using Jint.Runtime.References; namespace Jint.Pooling { /// - /// Cache reusable instances as we allocate them a lot. + /// Cache reusable instances as we allocate them a lot. /// internal sealed class ArgumentsInstancePool { diff --git a/Jint/Pooling/ReferencePool.cs b/Jint/Pooling/ReferencePool.cs index 24e10fdd77..97b1a16695 100644 --- a/Jint/Pooling/ReferencePool.cs +++ b/Jint/Pooling/ReferencePool.cs @@ -1,5 +1,5 @@ using Jint.Native; -using Jint.Runtime.References; +using Jint.Runtime; namespace Jint.Pooling { diff --git a/Jint/Runtime/DefaultReferenceResolver.cs b/Jint/Runtime/DefaultReferenceResolver.cs index d4b1aa7254..d627a270ed 100644 --- a/Jint/Runtime/DefaultReferenceResolver.cs +++ b/Jint/Runtime/DefaultReferenceResolver.cs @@ -1,6 +1,5 @@ using Jint.Native; using Jint.Runtime.Interop; -using Jint.Runtime.References; namespace Jint.Runtime { diff --git a/Jint/Runtime/Environments/Binding.cs b/Jint/Runtime/Environments/Binding.cs index b71163a506..13d5f12160 100644 --- a/Jint/Runtime/Environments/Binding.cs +++ b/Jint/Runtime/Environments/Binding.cs @@ -4,7 +4,7 @@ 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, diff --git a/Jint/Runtime/ExceptionHelper.cs b/Jint/Runtime/ExceptionHelper.cs index 475edbdd70..c86307928d 100644 --- a/Jint/Runtime/ExceptionHelper.cs +++ b/Jint/Runtime/ExceptionHelper.cs @@ -7,7 +7,6 @@ using Jint.Native.Error; using Jint.Runtime.CallStack; using Jint.Runtime.Modules; -using Jint.Runtime.References; namespace Jint.Runtime { diff --git a/Jint/Runtime/Interop/ClrFunction.cs b/Jint/Runtime/Interop/ClrFunction.cs index fadb94c3b2..0c46f33347 100644 --- a/Jint/Runtime/Interop/ClrFunction.cs +++ b/Jint/Runtime/Interop/ClrFunction.cs @@ -30,7 +30,7 @@ public 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); diff --git a/Jint/Runtime/Interop/ClrHelper.cs b/Jint/Runtime/Interop/ClrHelper.cs index f59fcc1faa..a17bc6665c 100644 --- a/Jint/Runtime/Interop/ClrHelper.cs +++ b/Jint/Runtime/Interop/ClrHelper.cs @@ -4,9 +4,9 @@ public class ClrHelper { - private readonly InteropOptions _interopOptions; + private readonly Options.InteropOptions _interopOptions; - internal ClrHelper(InteropOptions interopOptions) + internal ClrHelper(Options.InteropOptions interopOptions) { _interopOptions = interopOptions; } diff --git a/Jint/Runtime/Interop/IReferenceResolver.cs b/Jint/Runtime/Interop/IReferenceResolver.cs index b2f163b390..3e39af9d76 100644 --- a/Jint/Runtime/Interop/IReferenceResolver.cs +++ b/Jint/Runtime/Interop/IReferenceResolver.cs @@ -1,5 +1,4 @@ using Jint.Native; -using Jint.Runtime.References; namespace Jint.Runtime.Interop { diff --git a/Jint/Runtime/Interop/TypeResolver.cs b/Jint/Runtime/Interop/TypeResolver.cs index eb212b5bf0..3101affe4a 100644 --- a/Jint/Runtime/Interop/TypeResolver.cs +++ b/Jint/Runtime/Interop/TypeResolver.cs @@ -16,9 +16,9 @@ public sealed class TypeResolver /// /// 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 configuration. + /// By default allows all but will also be limited by configuration. /// - /// + /// public Predicate MemberFilter { get; set; } = _ => true; internal bool Filter(Engine engine, MemberInfo m) diff --git a/Jint/Runtime/Interpreter/Expressions/BindingPatternAssignmentExpression.cs b/Jint/Runtime/Interpreter/Expressions/BindingPatternAssignmentExpression.cs index 82bbb939b8..60fa18cbb6 100644 --- a/Jint/Runtime/Interpreter/Expressions/BindingPatternAssignmentExpression.cs +++ b/Jint/Runtime/Interpreter/Expressions/BindingPatternAssignmentExpression.cs @@ -3,7 +3,6 @@ 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 diff --git a/Jint/Runtime/Interpreter/Expressions/JintAssignmentExpression.cs b/Jint/Runtime/Interpreter/Expressions/JintAssignmentExpression.cs index 9fea6534c4..0a6c0f3a28 100644 --- a/Jint/Runtime/Interpreter/Expressions/JintAssignmentExpression.cs +++ b/Jint/Runtime/Interpreter/Expressions/JintAssignmentExpression.cs @@ -3,7 +3,6 @@ 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 diff --git a/Jint/Runtime/Interpreter/Expressions/JintCallExpression.cs b/Jint/Runtime/Interpreter/Expressions/JintCallExpression.cs index c5cf9c5f0b..b7d791f47d 100644 --- a/Jint/Runtime/Interpreter/Expressions/JintCallExpression.cs +++ b/Jint/Runtime/Interpreter/Expressions/JintCallExpression.cs @@ -6,7 +6,6 @@ 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 diff --git a/Jint/Runtime/Interpreter/Expressions/JintExpression.cs b/Jint/Runtime/Interpreter/Expressions/JintExpression.cs index 8d31bc0d00..9dc9f16931 100644 --- a/Jint/Runtime/Interpreter/Expressions/JintExpression.cs +++ b/Jint/Runtime/Interpreter/Expressions/JintExpression.cs @@ -4,7 +4,6 @@ using Jint.Native; using Jint.Native.Iterator; using Jint.Native.Number; -using Jint.Runtime.References; namespace Jint.Runtime.Interpreter.Expressions { diff --git a/Jint/Runtime/Interpreter/Expressions/JintMemberExpression.cs b/Jint/Runtime/Interpreter/Expressions/JintMemberExpression.cs index cd1442dfeb..0cae4b962b 100644 --- a/Jint/Runtime/Interpreter/Expressions/JintMemberExpression.cs +++ b/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 { diff --git a/Jint/Runtime/Interpreter/Expressions/JintTaggedTemplateExpression.cs b/Jint/Runtime/Interpreter/Expressions/JintTaggedTemplateExpression.cs index 95e34407b4..02f422fade 100644 --- a/Jint/Runtime/Interpreter/Expressions/JintTaggedTemplateExpression.cs +++ b/Jint/Runtime/Interpreter/Expressions/JintTaggedTemplateExpression.cs @@ -2,7 +2,6 @@ using Jint.Native; using Jint.Native.Object; using Jint.Runtime.Descriptors; -using Jint.Runtime.References; namespace Jint.Runtime.Interpreter.Expressions; diff --git a/Jint/Runtime/Interpreter/Expressions/JintUnaryExpression.cs b/Jint/Runtime/Interpreter/Expressions/JintUnaryExpression.cs index 50f7db3a1b..99611f7f2e 100644 --- a/Jint/Runtime/Interpreter/Expressions/JintUnaryExpression.cs +++ b/Jint/Runtime/Interpreter/Expressions/JintUnaryExpression.cs @@ -2,7 +2,6 @@ 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; diff --git a/Jint/Runtime/Interpreter/Expressions/JintUpdateExpression.cs b/Jint/Runtime/Interpreter/Expressions/JintUpdateExpression.cs index ddcec5bcb3..6e8646682b 100644 --- a/Jint/Runtime/Interpreter/Expressions/JintUpdateExpression.cs +++ b/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 { diff --git a/Jint/Runtime/Interpreter/Statements/JintForInForOfStatement.cs b/Jint/Runtime/Interpreter/Statements/JintForInForOfStatement.cs index da7c2066a2..2836d53eb6 100644 --- a/Jint/Runtime/Interpreter/Statements/JintForInForOfStatement.cs +++ b/Jint/Runtime/Interpreter/Statements/JintForInForOfStatement.cs @@ -4,7 +4,6 @@ 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 diff --git a/Jint/Runtime/Interpreter/Statements/JintVariableDeclaration.cs b/Jint/Runtime/Interpreter/Statements/JintVariableDeclaration.cs index 4198c4bf8a..7b5c17bfec 100644 --- a/Jint/Runtime/Interpreter/Statements/JintVariableDeclaration.cs +++ b/Jint/Runtime/Interpreter/Statements/JintVariableDeclaration.cs @@ -2,7 +2,6 @@ using Jint.Native; using Jint.Native.Function; using Jint.Runtime.Interpreter.Expressions; -using Jint.Runtime.References; namespace Jint.Runtime.Interpreter.Statements { diff --git a/Jint/ModuleBuilder.cs b/Jint/Runtime/Modules/ModuleBuilder.cs similarity index 93% rename from Jint/ModuleBuilder.cs rename to Jint/Runtime/Modules/ModuleBuilder.cs index acf3dbca40..49a7556ad6 100644 --- a/Jint/ModuleBuilder.cs +++ b/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 _sourceRaw = new(); private readonly Dictionary _exports = new(StringComparer.Ordinal); private readonly ParserOptions _options; @@ -37,7 +34,7 @@ public ModuleBuilder AddSource(string code) return this; } - public ModuleBuilder AddModule(Module module) + public ModuleBuilder AddModule(global::Esprima.Ast.Module module) { if (_sourceRaw.Count > 0) { @@ -126,12 +123,12 @@ public ModuleBuilder WithOptions(Action configure) 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())); + return new global::Esprima.Ast.Module(NodeList.Create(Array.Empty())); } var javaScriptParser = new JavaScriptParser(_options); diff --git a/Jint/Runtime/References/Reference.cs b/Jint/Runtime/Reference.cs similarity index 98% rename from Jint/Runtime/References/Reference.cs rename to Jint/Runtime/Reference.cs index 8c58479fdf..ac8226f1a3 100644 --- a/Jint/Runtime/References/Reference.cs +++ b/Jint/Runtime/Reference.cs @@ -4,7 +4,7 @@ using Jint.Runtime.Environments; using Environment = Jint.Runtime.Environments.Environment; -namespace Jint.Runtime.References; +namespace Jint.Runtime; /// /// https://tc39.es/ecma262/#sec-reference-record-specification-type diff --git a/Jint/StrictModeScope.cs b/Jint/StrictModeScope.cs index c512b8a18b..f5bca0ae75 100644 --- a/Jint/StrictModeScope.cs +++ b/Jint/StrictModeScope.cs @@ -3,7 +3,7 @@ namespace Jint { [StructLayout(LayoutKind.Auto)] - public readonly struct StrictModeScope : IDisposable + internal readonly struct StrictModeScope : IDisposable { private readonly bool _strict; private readonly bool _force;