using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using Jint.Native;
using Jint.Native.Function;
using Jint.Native.Generator;
using Jint.Native.Object;
using Jint.Native.Promise;
using Jint.Native.Symbol;
using Jint.Pooling;
using Jint.Runtime;
using Jint.Runtime.CallStack;
using Jint.Runtime.Debugger;
using Jint.Runtime.Descriptors;
using Jint.Runtime.Environments;
using Jint.Runtime.Interop;
using Jint.Runtime.Interop.Reflection;
using Jint.Runtime.Interpreter;
using Jint.Runtime.Interpreter.Expressions;
using Environment = Jint.Runtime.Environments.Environment;
namespace Jint
{
///
/// Engine is the main API to JavaScript interpretation. Engine instances are not thread-safe.
///
[DebuggerTypeProxy(typeof(EngineDebugView))]
public sealed partial class Engine : IDisposable
{
private static readonly Options _defaultEngineOptions = new();
private readonly ParserOptions _defaultParserOptions;
private readonly Parser _defaultParser;
private readonly ExecutionContextStack _executionContexts;
private JsValue _completionValue = JsValue.Undefined;
internal EvaluationContext? _activeEvaluationContext;
internal ErrorDispatchInfo? _error;
private readonly EventLoop _eventLoop = new();
private readonly Agent _agent = new();
// lazy properties
private DebugHandler? _debugger;
// cached access
internal readonly IObjectConverter[]? _objectConverters;
internal readonly Constraint[] _constraints;
internal readonly bool _isDebugMode;
internal readonly bool _isStrict;
private bool _customResolver;
internal readonly IReferenceResolver _referenceResolver;
internal readonly ReferencePool _referencePool;
internal readonly ArgumentsInstancePool _argumentsInstancePool;
internal readonly JsValueArrayPool _jsValueArrayPool;
internal readonly ExtensionMethodCache _extensionMethods;
public ITypeConverter TypeConverter { get; internal set; }
// cache of types used when resolving CLR type names
internal readonly Dictionary TypeCache = new(StringComparer.Ordinal);
// we use registered type reference as prototype if it's known
internal Dictionary? _typeReferences;
// cache for already wrapped CLR objects to keep object identity
internal ConditionalWeakTable