using System; using System.Buffers; using System.Collections; using System.Collections.Concurrent; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Dynamic; using System.Globalization; using System.IO; using System.Linq; using System.Linq.Expressions; using System.Numerics; using System.Reflection; using System.Resources; using System.Runtime.CompilerServices; using System.Runtime.ExceptionServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using System.Text; using System.Text.Encodings.Web; using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; using Esprima; using Esprima.Ast; using Esprima.Utils; using Jint.Collections; using Jint.Constraints; using Jint.Extensions; using Jint.Native; using Jint.Native.AggregateError; using Jint.Native.Array; using Jint.Native.ArrayBuffer; using Jint.Native.AsyncFunction; using Jint.Native.BigInt; using Jint.Native.Boolean; using Jint.Native.DataView; using Jint.Native.Date; using Jint.Native.Error; using Jint.Native.FinalizationRegistry; using Jint.Native.Function; using Jint.Native.Generator; using Jint.Native.Global; using Jint.Native.Intl; using Jint.Native.Iterator; using Jint.Native.Json; using Jint.Native.Map; using Jint.Native.Math; using Jint.Native.Number; using Jint.Native.Number.Dtoa; using Jint.Native.Object; using Jint.Native.Promise; using Jint.Native.Proxy; using Jint.Native.Reflect; using Jint.Native.RegExp; using Jint.Native.Set; using Jint.Native.ShadowRealm; using Jint.Native.SharedArrayBuffer; using Jint.Native.String; using Jint.Native.Symbol; using Jint.Native.TypedArray; using Jint.Native.WeakMap; using Jint.Native.WeakRef; using Jint.Native.WeakSet; using Jint.Pooling; using Jint.Runtime; using Jint.Runtime.CallStack; using Jint.Runtime.Debugger; using Jint.Runtime.Descriptors; using Jint.Runtime.Descriptors.Specialized; using Jint.Runtime.Environments; using Jint.Runtime.Interop; using Jint.Runtime.Interop.Reflection; using Jint.Runtime.Interpreter; using Jint.Runtime.Interpreter.Expressions; using Jint.Runtime.Interpreter.Statements; using Jint.Runtime.Modules; using Microsoft.CodeAnalysis; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: InternalsVisibleTo("Jint.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100bf2553c9f214cb21f1f64ed62cadad8fe4f2fa11322a5dfa1d650743145c6085aba05b145b29867af656e0bb9bfd32f5d0deb1668263a38233e7e8e5bad1a3c6edd3f2ec6c512668b4aa797283101444628650949641b4f7cb16707efba542bb754afe87ce956f3a5d43f450d14364eb9571cbf213d1061852fb9dd47a6c05c4")] [assembly: InternalsVisibleTo("Jint.Tests.Test262, PublicKey=0024000004800000940000000602000000240000525341310004000001000100bf2553c9f214cb21f1f64ed62cadad8fe4f2fa11322a5dfa1d650743145c6085aba05b145b29867af656e0bb9bfd32f5d0deb1668263a38233e7e8e5bad1a3c6edd3f2ec6c512668b4aa797283101444628650949641b4f7cb16707efba542bb754afe87ce956f3a5d43f450d14364eb9571cbf213d1061852fb9dd47a6c05c4")] [assembly: InternalsVisibleTo("Jint.Benchmark, PublicKey=0024000004800000940000000602000000240000525341310004000001000100bf2553c9f214cb21f1f64ed62cadad8fe4f2fa11322a5dfa1d650743145c6085aba05b145b29867af656e0bb9bfd32f5d0deb1668263a38233e7e8e5bad1a3c6edd3f2ec6c512668b4aa797283101444628650949641b4f7cb16707efba542bb754afe87ce956f3a5d43f450d14364eb9571cbf213d1061852fb9dd47a6c05c4")] [assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")] [assembly: AssemblyCompany("Sebastien Ros")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyCopyright("Sebastien Ros")] [assembly: AssemblyDescription("Javascript interpreter for .NET.")] [assembly: AssemblyFileVersion("3.1.0.0")] [assembly: AssemblyInformationalVersion("3.1.5+6cb44564e35d18646604dedb002170be1fd941d9")] [assembly: AssemblyProduct("Jint")] [assembly: AssemblyTitle("Jint")] [assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/sebastienros/jint")] [assembly: NeutralResourcesLanguage("en-US")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("3.1.5.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] [module: SkipLocalsInit] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] internal sealed class ScopedRefAttribute : Attribute { } [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace System.Runtime.Versioning { [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Module | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Interface, AllowMultiple = true, Inherited = false)] [ExcludeFromCodeCoverage] [Conditional("MULTI_TARGETING_SUPPORT_ATTRIBUTES")] internal sealed class ObsoletedOSPlatformAttribute : Attribute { public string? Message { get; } public string? Url { get; set; } public ObsoletedOSPlatformAttribute(string platformName) { } public ObsoletedOSPlatformAttribute(string platformName, string? message) { Message = message; } } } namespace System.Runtime.CompilerServices2 { [AttributeUsage(AttributeTargets.Struct, AllowMultiple = false)] [ExcludeFromCodeCoverage] [Conditional("MULTI_TARGETING_SUPPORT_ATTRIBUTES")] internal sealed class InlineArrayAttribute : Attribute { public int Length { get; } public InlineArrayAttribute(int length) { Length = length; } } } namespace System.Runtime.CompilerServices { [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Interface, Inherited = false)] [ExcludeFromCodeCoverage] internal sealed class CollectionBuilderAttribute : Attribute { public Type BuilderType { get; } public string MethodName { get; } public CollectionBuilderAttribute(Type builderType, string methodName) { BuilderType = builderType; MethodName = methodName; } } [AttributeUsage(AttributeTargets.All, AllowMultiple = true, Inherited = false)] [ExcludeFromCodeCoverage] internal sealed class CompilerFeatureRequiredAttribute : Attribute { public const string RefStructs = "RefStructs"; public const string RequiredMembers = "RequiredMembers"; public string FeatureName { get; } public bool IsOptional { get; set; } public CompilerFeatureRequiredAttribute(string featureName) { FeatureName = featureName; } } [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false, Inherited = false)] [ExcludeFromCodeCoverage] internal sealed class RequiredMemberAttribute : Attribute { } [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] [ExcludeFromCodeCoverage] [Conditional("MULTI_TARGETING_SUPPORT_ATTRIBUTES")] internal sealed class DisableRuntimeMarshallingAttribute : Attribute { } [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)] [ExcludeFromCodeCoverage] [Conditional("MULTI_TARGETING_SUPPORT_ATTRIBUTES")] internal sealed class UnsafeAccessorAttribute : Attribute { public UnsafeAccessorKind Kind { get; } public string? Name { get; set; } public UnsafeAccessorAttribute(UnsafeAccessorKind kind) { Kind = kind; } } internal enum UnsafeAccessorKind { Constructor, Method, StaticMethod, Field, StaticField } } namespace System.Diagnostics.CodeAnalysis { [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Module | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Interface | AttributeTargets.Delegate, Inherited = false)] [ExcludeFromCodeCoverage] internal sealed class ExperimentalAttribute : Attribute { public string DiagnosticId { get; } public string? UrlFormat { get; set; } public ExperimentalAttribute(string diagnosticId) { DiagnosticId = diagnosticId; } } [AttributeUsage(AttributeTargets.Constructor, AllowMultiple = false, Inherited = false)] [ExcludeFromCodeCoverage] internal sealed class SetsRequiredMembersAttribute : Attribute { } [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] [ExcludeFromCodeCoverage] internal sealed class StringSyntaxAttribute : Attribute { public const string CompositeFormat = "CompositeFormat"; public const string DateOnlyFormat = "DateOnlyFormat"; public const string DateTimeFormat = "DateTimeFormat"; public const string EnumFormat = "EnumFormat"; public const string GuidFormat = "GuidFormat"; public const string Json = "Json"; public const string NumericFormat = "NumericFormat"; public const string Regex = "Regex"; public const string TimeOnlyFormat = "TimeOnlyFormat"; public const string TimeSpanFormat = "TimeSpanFormat"; public const string Uri = "Uri"; public const string Xml = "Xml"; public string Syntax { get; } public object?[] Arguments { get; } public StringSyntaxAttribute(string syntax) { Syntax = syntax; Arguments = new object[0]; } public StringSyntaxAttribute(string syntax, params object?[] arguments) { Syntax = syntax; Arguments = arguments; } } [AttributeUsage(AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] [ExcludeFromCodeCoverage] internal sealed class UnscopedRefAttribute : Attribute { } [AttributeUsage(AttributeTargets.Class | AttributeTargets.Constructor | AttributeTargets.Method, Inherited = false)] [ExcludeFromCodeCoverage] [Conditional("MULTI_TARGETING_SUPPORT_ATTRIBUTES")] internal sealed class RequiresDynamicCodeAttribute : Attribute { public string Message { get; } public string? Url { get; set; } public RequiresDynamicCodeAttribute(string message) { Message = message; } } } namespace System.Text { internal ref struct ValueStringBuilder { private char[]? _arrayToReturnToPool; private Span _chars; private int _pos; public int Length { get { return _pos; } set { _pos = value; } } public int Capacity => _chars.Length; public ref char this[int index] => ref _chars[index]; public Span RawChars => _chars; public ValueStringBuilder(Span initialBuffer) { _arrayToReturnToPool = null; _chars = initialBuffer; _pos = 0; } public ValueStringBuilder(int initialCapacity) { _arrayToReturnToPool = ArrayPool.Shared.Rent(initialCapacity); _chars = _arrayToReturnToPool; _pos = 0; } public void EnsureCapacity(int capacity) { if ((uint)capacity > (uint)_chars.Length) { Grow(capacity - _pos); } } public ref char GetPinnableReference() { return ref MemoryMarshal.GetReference(_chars); } public ref char GetPinnableReference(bool terminate) { if (terminate) { EnsureCapacity(Length + 1); _chars[Length] = '\0'; } return ref MemoryMarshal.GetReference(_chars); } public override string ToString() { string result = _chars.Slice(0, _pos).ToString(); Dispose(); return result; } public ReadOnlySpan AsSpan(bool terminate) { if (terminate) { EnsureCapacity(Length + 1); _chars[Length] = '\0'; } return _chars.Slice(0, _pos); } public ReadOnlySpan AsSpan() { return _chars.Slice(0, _pos); } public ReadOnlySpan AsSpan(int start) { return _chars.Slice(start, _pos - start); } public ReadOnlySpan AsSpan(int start, int length) { return _chars.Slice(start, length); } public void Reverse() { _chars.Slice(0, _pos).Reverse(); } public bool TryCopyTo(Span destination, out int charsWritten) { if (_chars.Slice(0, _pos).TryCopyTo(destination)) { charsWritten = _pos; Dispose(); return true; } charsWritten = 0; Dispose(); return false; } public void Insert(int index, char value, int count) { if (_pos > _chars.Length - count) { Grow(count); } int length = _pos - index; _chars.Slice(index, length).CopyTo(_chars.Slice(index + count)); _chars.Slice(index, count).Fill(value); _pos += count; } public void Insert(int index, string? s) { if (s != null) { int length = s.Length; if (_pos > _chars.Length - length) { Grow(length); } int length2 = _pos - index; _chars.Slice(index, length2).CopyTo(_chars.Slice(index + length)); s.CopyTo(_chars.Slice(index)); _pos += length; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Append(char c) { int pos = _pos; Span chars = _chars; if ((uint)pos < (uint)chars.Length) { chars[pos] = c; _pos = pos + 1; } else { GrowAndAppend(c); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Append(string? s) { if (s != null) { int pos = _pos; if (s.Length == 1 && (uint)pos < (uint)_chars.Length) { _chars[pos] = s[0]; _pos = pos + 1; } else { AppendSlow(s); } } } private void AppendSlow(string s) { int pos = _pos; if (pos > _chars.Length - s.Length) { Grow(s.Length); } s.CopyTo(_chars.Slice(pos)); _pos += s.Length; } public void Append(char c, int count) { if (_pos > _chars.Length - count) { Grow(count); } Span span = _chars.Slice(_pos, count); for (int i = 0; i < span.Length; i++) { span[i] = c; } _pos += count; } public unsafe void Append(char* value, int length) { if (_pos > _chars.Length - length) { Grow(length); } Span span = _chars.Slice(_pos, length); for (int i = 0; i < span.Length; i++) { span[i] = *(value++); } _pos += length; } public void Append(scoped ReadOnlySpan value) { if (_pos > _chars.Length - value.Length) { Grow(value.Length); } value.CopyTo(_chars.Slice(_pos)); _pos += value.Length; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public Span AppendSpan(int length) { int pos = _pos; if (pos > _chars.Length - length) { Grow(length); } _pos = pos + length; return _chars.Slice(pos, length); } [MethodImpl(MethodImplOptions.NoInlining)] private void GrowAndAppend(char c) { Grow(1); Append(c); } [MethodImpl(MethodImplOptions.NoInlining)] private void Grow(int additionalCapacityBeyondPos) { int minimumLength = (int)Math.Max((uint)(_pos + additionalCapacityBeyondPos), Math.Min((uint)(_chars.Length * 2), 2147483591u)); char[] array = ArrayPool.Shared.Rent(minimumLength); _chars.Slice(0, _pos).CopyTo(array); char[] arrayToReturnToPool = _arrayToReturnToPool; _chars = (_arrayToReturnToPool = array); if (arrayToReturnToPool != null) { ArrayPool.Shared.Return(arrayToReturnToPool); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Dispose() { char[] arrayToReturnToPool = _arrayToReturnToPool; this = default(System.Text.ValueStringBuilder); if (arrayToReturnToPool != null) { ArrayPool.Shared.Return(arrayToReturnToPool); } } } } namespace System.Buffers { internal static class SearchValues { internal static SearchValues Create(string input) { return new SearchValues(input.AsSpan()); } internal static SearchValues Create(ReadOnlySpan input) { return new SearchValues(input); } } internal sealed class SearchValues { private readonly bool[] _data; private readonly char _min; private readonly char _max; internal SearchValues(ReadOnlySpan input) { _min = '\uffff'; _max = '\0'; ReadOnlySpan readOnlySpan = input; for (int i = 0; i < readOnlySpan.Length; i++) { char val = readOnlySpan[i]; _min = (char)Math.Min(_min, val); _max = (char)Math.Max(_max, val); } _data = new bool[_max - _min + 1]; readOnlySpan = input; for (int i = 0; i < readOnlySpan.Length; i++) { char c = readOnlySpan[i]; _data[c - _min] = true; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Contains(char c) { uint num = (uint)(c - _min); bool[] data = _data; if (num < data.Length) { return data[num]; } return false; } } } namespace Jint { internal sealed class Agent { private readonly List _keptAlive = new List(); public void AddToKeptObjects(JsValue target) { _keptAlive.Add(target); } public void ClearKeptObjects() { _keptAlive.Clear(); } } public static class AstExtensions { internal readonly record struct Record(JsValue Key, ScriptFunction Closure); private sealed class MinimalSyntaxElement : SyntaxElement { public MinimalSyntaxElement(in Location location) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) base.Location = location; } } private sealed class PrivateIdentifierValidator : AstVisitor { private readonly Realm _realm; private HashSet? _privateNames; public PrivateIdentifierValidator(Realm realm, HashSet? privateNames) { _realm = realm; _privateNames = privateNames; } protected override object VisitPrivateIdentifier(PrivateIdentifier privateIdentifier) { if (_privateNames == null || !_privateNames.Contains(privateIdentifier)) { Throw(_realm, privateIdentifier); } return privateIdentifier; } protected override object VisitClassBody(ClassBody classBody) { HashSet privateNames = _privateNames; _privateNames = new HashSet(PrivateIdentifierNameComparer._instance); ((Node)(object)classBody).PrivateBoundIdentifiers(_privateNames); ((AstVisitor)this).VisitClassBody(classBody); _privateNames = privateNames; return classBody; } [MethodImpl(MethodImplOptions.NoInlining)] private static void Throw(Realm r, PrivateIdentifier id) { ExceptionHelper.ThrowSyntaxError(r, "Private field '#" + id.Name + "' must be declared in an enclosing class"); } } public static JsValue GetKey(this T property, Engine engine) where T : IProperty { return ((IProperty)property).Key.GetKey(engine, ((IProperty)property).Computed); } public static JsValue GetKey(this Expression expression, Engine engine, bool resolveComputed = false) { //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) JsValue jsValue = expression.TryGetKey(engine, resolveComputed); if ((object)jsValue != null) { return TypeConverter.ToPropertyKey(jsValue); } ExceptionHelper.ThrowArgumentException("Unable to extract correct key, node type: " + ((object)((Node)expression).Type/*cast due to .constrained prefix*/).ToString()); return JsValue.Undefined; } internal static JsValue TryGetKey(this T property, Engine engine) where T : IProperty { return ((IProperty)property).Key.TryGetKey(engine, ((IProperty)property).Computed); } internal static JsValue TryGetKey(this T expression, Engine engine, bool resolveComputed) where T : Expression { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Invalid comparison between Unknown and I4 object obj = expression; Literal val = (Literal)((obj is Literal) ? obj : null); if (val != null) { return ((int)val.TokenType == 5) ? JsValue.Null : ((JsValue)LiteralKeyToString(val)); } if (!resolveComputed) { object obj2 = expression; Identifier val2 = (Identifier)((obj2 is Identifier) ? obj2 : null); if (val2 != null) { return val2.Name; } } object obj3 = expression; PrivateIdentifier val3 = (PrivateIdentifier)((obj3 is PrivateIdentifier) ? obj3 : null); if (val3 != null) { return engine.ExecutionContext.PrivateEnvironment.Names[val3]; } if (resolveComputed) { return TryGetComputedPropertyKey(expression, engine); } return JsValue.Undefined; } private static JsValue TryGetComputedPropertyKey(T expression, Engine engine) where T : Expression { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Invalid comparison between Unknown and I4 //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Invalid comparison between Unknown and I4 //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Invalid comparison between Unknown and I4 //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Invalid comparison between Unknown and I4 //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Invalid comparison between Unknown and I4 //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Invalid comparison between Unknown and I4 //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Invalid comparison between Unknown and I4 //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Invalid comparison between Unknown and I4 //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Invalid comparison between Unknown and I4 //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Invalid comparison between Unknown and I4 //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Invalid comparison between Unknown and I4 //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Invalid comparison between Unknown and I4 Nodes type = ((Node)(object)expression).Type; if ((int)type <= 16) { if ((int)type <= 7) { if (type - 3 <= 1 || (int)type == 7) { goto IL_0053; } } else if ((int)type == 10 || (int)type == 16) { goto IL_0053; } } else if ((int)type <= 43) { if (type - 31 <= 1 || type - 42 <= 1) { goto IL_0053; } } else if ((int)type == 63 || type - 67 <= 1 || (int)type == 73) { goto IL_0053; } bool flag = false; goto IL_0059; IL_0053: flag = true; goto IL_0059; IL_0059: if (flag) { EvaluationContext activeEvaluationContext = engine._activeEvaluationContext; return JintExpression.Build((Expression)(object)expression).GetValue(activeEvaluationContext); } return JsValue.Undefined; } [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static bool IsFunctionDefinition(this T node) where T : Node { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Invalid comparison between Unknown and I4 //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Invalid comparison between Unknown and I4 //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Invalid comparison between Unknown and I4 Nodes type = ((Node)node).Type; if ((int)type == 3 || (int)type == 15 || (int)type == 31) { return true; } return false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static bool IsConstantDeclaration(this Declaration d) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Invalid comparison between Unknown and I4 VariableDeclaration val = (VariableDeclaration)(object)((d is VariableDeclaration) ? d : null); if (val != null) { return (int)val.Kind == 2; } return false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static bool HasName(this T node) where T : Node { if (!node.IsFunctionDefinition()) { return false; } object obj = node; object obj2 = ((obj is IFunction) ? obj : null); if (((obj2 != null) ? ((IFunction)obj2).Id : null) != null) { return true; } object obj3 = node; object obj4 = ((obj3 is ClassExpression) ? obj3 : null); if (((obj4 != null) ? ((ClassExpression)obj4).Id : null) != null) { return true; } return false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static bool IsAnonymousFunctionDefinition(this T node) where T : Node { if (!node.IsFunctionDefinition()) { return false; } if (node.HasName()) { return false; } return true; } [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static bool IsOptional(this T node) where T : Expression { object obj = node; MemberExpression val = (MemberExpression)((obj is MemberExpression) ? obj : null); if (val != null) { if (val.Optional) { goto IL_0030; } } else { object obj2 = node; CallExpression val2 = (CallExpression)((obj2 is CallExpression) ? obj2 : null); if (val2 != null && val2.Optional) { goto IL_0030; } } return false; IL_0030: return true; } [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static string LiteralKeyToString(Literal literal) { if (literal.Value is double num) { return TypeConverter.ToString(num); } return (literal.Value as string) ?? Convert.ToString(literal.Value, null) ?? ""; } internal static void GetBoundNames(this VariableDeclaration variableDeclaration, List target) { ref NodeList declarations = variableDeclaration.Declarations; for (int i = 0; i < declarations.Count; i++) { declarations[i].Id.GetBoundNames(target); } } internal static void GetBoundNames(this Node? parameter, List target) { //IL_0004: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Invalid comparison between Unknown and I4 //IL_00ea: Unknown result type (might be due to invalid IL or missing references) //IL_00f5: Expected O, but got Unknown if (parameter == null || (int)parameter.Type == 41) { return; } Identifier val = (Identifier)(object)((parameter is Identifier) ? parameter : null); if (val != null) { target.Add(val.Name); return; } VariableDeclaration val2 = (VariableDeclaration)(object)((parameter is VariableDeclaration) ? parameter : null); if (val2 != null) { val2.GetBoundNames(target); return; } while (true) { Identifier val3 = (Identifier)(object)((parameter is Identifier) ? parameter : null); if (val3 != null) { target.Add(val3.Name); return; } RestElement val4 = (RestElement)(object)((parameter is RestElement) ? parameter : null); if (val4 != null) { parameter = val4.Argument; continue; } ArrayPattern val5 = (ArrayPattern)(object)((parameter is ArrayPattern) ? parameter : null); if (val5 != null) { ref NodeList elements = val5.Elements; for (int i = 0; i < elements.Count; i++) { elements[i].GetBoundNames(target); } return; } ObjectPattern val6 = (ObjectPattern)(object)((parameter is ObjectPattern) ? parameter : null); if (val6 != null) { ref NodeList properties = val6.Properties; for (int j = 0; j < properties.Count; j++) { Node val7 = properties[j]; Property val8 = (Property)(object)((val7 is Property) ? val7 : null); if (val8 != null) { val8.Value.GetBoundNames(target); } else { ((Node?)(RestElement)val7).GetBoundNames(target); } } return; } AssignmentPattern val9 = (AssignmentPattern)(object)((parameter is AssignmentPattern) ? parameter : null); if (val9 == null) { break; } parameter = val9.Left; } ClassDeclaration val10 = (ClassDeclaration)(object)((parameter is ClassDeclaration) ? parameter : null); if (val10 != null) { Identifier id = val10.Id; string text = ((id != null) ? id.Name : null); if (text != null) { target.Add(text); } } } internal static void PrivateBoundIdentifiers(this Node parameter, HashSet target) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Invalid comparison between Unknown and I4 //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Expected O, but got Unknown //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Invalid comparison between Unknown and I4 //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Invalid comparison between Unknown and I4 //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Invalid comparison between Unknown and I4 //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Unknown result type (might be due to invalid IL or missing references) if ((int)parameter.Type == 49) { target.Add((PrivateIdentifier)parameter); return; } Nodes type = parameter.Type; if (((int)type == 0 || (int)type == 45 || (int)type == 52) ? true : false) { Expression key = ((ClassProperty)parameter).Key; PrivateIdentifier val = (PrivateIdentifier)(object)((key is PrivateIdentifier) ? key : null); if (val != null) { target.Add(val); } } else if ((int)parameter.Type == 13) { ref NodeList body = ((ClassBody)parameter).Body; for (int i = 0; i < body.Count; i++) { ((Node)(object)body[i]).PrivateBoundIdentifiers(target); } } } internal static void BindingInitialization(this Node? expression, EvaluationContext context, JsValue value, Jint.Runtime.Environments.Environment env) { Identifier val = (Identifier)(object)((expression is Identifier) ? expression : null); if (val != null) { ((DeclarativeEnvironment)env).CreateMutableBindingAndInitialize(val.Name, canBeDeleted: false, value); return; } BindingPattern val2 = (BindingPattern)(object)((expression is BindingPattern) ? expression : null); if (val2 != null) { DestructuringPatternAssignmentExpression.ProcessPatterns(context, val2, value, env); } } internal static Record DefineMethod(this T m, ObjectInstance obj, ObjectInstance? functionPrototype = null) where T : IProperty { Engine engine = obj.Engine; JsValue key = TypeConverter.ToPropertyKey(m.GetKey(engine)); Intrinsics intrinsics = engine.Realm.Intrinsics; Jint.Runtime.Environments.ExecutionContext executionContext = engine.ExecutionContext; Jint.Runtime.Environments.Environment lexicalEnvironment = executionContext.LexicalEnvironment; PrivateEnvironment privateEnvironment = executionContext.PrivateEnvironment; ObjectInstance functionPrototype2 = functionPrototype ?? intrinsics.Function.PrototypeObject; Node value = ((IProperty)m).Value; Node obj2 = ((value is IFunction) ? value : null); if (obj2 == null) { ExceptionHelper.ThrowSyntaxError(engine.Realm); } JintFunctionDefinition jintFunctionDefinition = new JintFunctionDefinition((IFunction)(object)obj2); ScriptFunction scriptFunction = intrinsics.Function.OrdinaryFunctionCreate(functionPrototype2, jintFunctionDefinition, jintFunctionDefinition.ThisMode, lexicalEnvironment, privateEnvironment); scriptFunction.MakeMethod(obj); return new Record(key, scriptFunction); } internal unsafe static void GetImportEntries(this ImportDeclaration import, List importEntries, HashSet requestedModules) { //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) string stringValue = import.Source.StringValue; NodeList specifiers = Unsafe.Read>((void*)import.Specifiers); ModuleImportAttribute[] attributes = GetAttributes(import.Attributes); requestedModules.Add(new ModuleRequest(stringValue, attributes)); Enumerator enumerator = specifiers.GetEnumerator(); try { while (enumerator.MoveNext()) { ImportDeclarationSpecifier current = enumerator.Current; ImportNamespaceSpecifier val = (ImportNamespaceSpecifier)(object)((current is ImportNamespaceSpecifier) ? current : null); if (val == null) { ImportSpecifier val2 = (ImportSpecifier)(object)((current is ImportSpecifier) ? current : null); if (val2 == null) { ImportDefaultSpecifier val3 = (ImportDefaultSpecifier)(object)((current is ImportDefaultSpecifier) ? current : null); if (val3 != null) { importEntries.Add(new ImportEntry(new ModuleRequest(stringValue, attributes), "default", ((Expression)(object)((ImportDeclarationSpecifier)val3).Local).GetModuleKey())); } } else { importEntries.Add(new ImportEntry(new ModuleRequest(stringValue, attributes), val2.Imported.GetModuleKey(), ((Expression)(object)((ImportDeclarationSpecifier)val2).Local).GetModuleKey())); } } else { importEntries.Add(new ImportEntry(new ModuleRequest(stringValue, attributes), "*", ((Expression)(object)((ImportDeclarationSpecifier)val).Local).GetModuleKey())); } } } finally { ((IDisposable)enumerator/*cast due to .constrained prefix*/).Dispose(); } } private static ModuleImportAttribute[] GetAttributes(in NodeList importAttributes) { if (importAttributes.Count == 0) { return Array.Empty(); } ModuleImportAttribute[] array = new ModuleImportAttribute[importAttributes.Count]; for (int i = 0; i < importAttributes.Count; i++) { ImportAttribute val = importAttributes[i]; array[i] = new ModuleImportAttribute(((object)val.Key).ToString(), val.Value.StringValue); } return array; } internal static void GetExportEntries(this ExportDeclaration export, List exportEntries, HashSet requestedModules) { ExportDefaultDeclaration val = (ExportDefaultDeclaration)(object)((export is ExportDefaultDeclaration) ? export : null); if (val == null) { ExportAllDeclaration val2 = (ExportAllDeclaration)(object)((export is ExportAllDeclaration) ? export : null); if (val2 == null) { ExportNamedDeclaration val3 = (ExportNamedDeclaration)(object)((export is ExportNamedDeclaration) ? export : null); if (val3 == null) { return; } ref NodeList specifiers = val3.Specifiers; if (specifiers.Count == 0) { ModuleRequest? obj; if (val3.Source == null) { obj = null; } else { Literal source = val3.Source; obj = new ModuleRequest((source != null) ? source.StringValue : null, Array.Empty()); } ModuleRequest? moduleRequest = obj; GetExportEntries(defaultExport: false, (StatementListItem)(object)val3.Declaration, exportEntries, moduleRequest); } else { for (int i = 0; i < specifiers.Count; i++) { ExportSpecifier val4 = specifiers[i]; if (val3.Source != null) { exportEntries.Add(new ExportEntry(val4.Exported.GetModuleKey(), new ModuleRequest(val3.Source.StringValue, Array.Empty()), val4.Local.GetModuleKey(), null)); } else { exportEntries.Add(new ExportEntry(val4.Exported.GetModuleKey(), null, null, val4.Local.GetModuleKey())); } } } if (val3.Source != null) { requestedModules.Add(new ModuleRequest(val3.Source.StringValue, Array.Empty())); } } else { requestedModules.Add(new ModuleRequest(val2.Source.StringValue, Array.Empty())); Expression exported = val2.Exported; exportEntries.Add(new ExportEntry((exported != null) ? exported.GetModuleKey() : null, new ModuleRequest(val2.Source.StringValue, Array.Empty()), "*", null)); } } else { GetExportEntries(defaultExport: true, val.Declaration, exportEntries); } } private static void GetExportEntries(bool defaultExport, StatementListItem declaration, List exportEntries, ModuleRequest? moduleRequest = null) { List exportNames = GetExportNames(declaration); if (exportNames.Count == 0) { if (defaultExport) { exportEntries.Add(new ExportEntry("default", null, null, "*default*")); } return; } for (int i = 0; i < exportNames.Count; i++) { Key key = exportNames[i]; string exportName = (defaultExport ? "default" : key.Name); exportEntries.Add(new ExportEntry(exportName, moduleRequest, null, key)); } } private static List GetExportNames(StatementListItem declaration) { List list = new List(); FunctionDeclaration val = (FunctionDeclaration)(object)((declaration is FunctionDeclaration) ? declaration : null); if (val == null) { ClassDeclaration val2 = (ClassDeclaration)(object)((declaration is ClassDeclaration) ? declaration : null); if (val2 == null) { ((VariableDeclaration)(object)((declaration is VariableDeclaration) ? declaration : null))?.GetBoundNames(list); } else { Identifier id = val2.Id; string text = ((id != null) ? id.Name : null); if (text != null) { list.Add(text); } } } else { Identifier id2 = val.Id; string text2 = ((id2 != null) ? id2.Name : null); if (text2 != null) { list.Add(text2); } } return list; } private static string GetModuleKey(this Expression expression) { Expression obj = ((expression is Identifier) ? expression : null); return ((obj != null) ? ((Identifier)obj).Name : null) ?? ((Literal)((expression is Literal) ? expression : null)).StringValue; } internal static SyntaxElement CreateLocationNode(in Location location) { return (SyntaxElement)(object)new MinimalSyntaxElement(in location); } internal static void AllPrivateIdentifiersValid(this Script script, Realm realm, HashSet? privateIdentifiers) { ((AstVisitor)new PrivateIdentifierValidator(realm, privateIdentifiers)).Visit((Node)(object)script); } } public static class ConstraintsOptionsExtensions { public static Options MaxStatements(this Options options, int maxStatements = 0) { options.WithoutConstraint((Constraint x) => x is MaxStatementsConstraint); if (maxStatements > 0 && maxStatements < int.MaxValue) { options.Constraint(new MaxStatementsConstraint(maxStatements)); } return options; } public static Options LimitMemory(this Options options, long memoryLimit) { options.WithoutConstraint((Constraint x) => x is MemoryLimitConstraint); if (memoryLimit > 0 && memoryLimit < int.MaxValue) { options.Constraint(new MemoryLimitConstraint(memoryLimit)); } return options; } public static Options TimeoutInterval(this Options options, TimeSpan timeoutInterval) { if (timeoutInterval > TimeSpan.Zero && timeoutInterval < TimeSpan.MaxValue) { options.Constraint(new TimeConstraint(timeoutInterval)); } return options; } public static Options CancellationToken(this Options options, CancellationToken cancellationToken) { options.WithoutConstraint((Constraint x) => x is CancellationConstraint); if (cancellationToken != default(CancellationToken)) { options.Constraint(new CancellationConstraint(cancellationToken)); } return options; } } public enum DeclarationBindingType { GlobalCode, FunctionCode, EvalCode } [DebuggerTypeProxy(typeof(EngineDebugView))] public sealed class Engine : IDisposable { public class AdvancedOperations { private readonly Engine _engine; public string StackTrace { get { //IL_0021: Unknown result type (might be due to invalid IL or missing references) SyntaxElement lastSyntaxElement = _engine._lastSyntaxElement; if (lastSyntaxElement == null) { return string.Empty; } return _engine.CallStack.BuildCallStackString(lastSyntaxElement.Location); } } internal AdvancedOperations(Engine engine) { _engine = engine; } public void ResetCallStack() { _engine.ResetCallStack(); } public void ProcessTasks() { _engine.RunAvailableContinuations(); } public ManualPromise RegisterPromise() { return _engine.RegisterPromise(); } } private sealed class AstAnalyzer { private static readonly bool _canCompileNegativeLookaroundAssertions; private readonly IPreparationOptions _preparationOptions; private readonly Dictionary _bindingNames = new Dictionary(StringComparer.Ordinal); private readonly Dictionary _regexes = new Dictionary(StringComparer.Ordinal); public AstAnalyzer(IPreparationOptions preparationOptions) { _preparationOptions = preparationOptions; } public void NodeVisitor(Node node) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Invalid comparison between Unknown and I4 //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Invalid comparison between Unknown and I4 //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Invalid comparison between Unknown and I4 //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Invalid comparison between Unknown and I4 //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Invalid comparison between Unknown and I4 //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Invalid comparison between Unknown and I4 //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Invalid comparison between Unknown and I4 //IL_01e5: Unknown result type (might be due to invalid IL or missing references) //IL_01ef: Expected O, but got Unknown //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Invalid comparison between Unknown and I4 //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: Expected O, but got Unknown //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Invalid comparison between Unknown and I4 //IL_01ce: Unknown result type (might be due to invalid IL or missing references) //IL_01d5: Expected O, but got Unknown //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Invalid comparison between Unknown and I4 //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Invalid comparison between Unknown and I4 //IL_02b0: Unknown result type (might be due to invalid IL or missing references) //IL_02b7: Expected O, but got Unknown //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Invalid comparison between Unknown and I4 //IL_01bc: Unknown result type (might be due to invalid IL or missing references) //IL_01c7: Expected O, but got Unknown //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Expected O, but got Unknown //IL_0208: Unknown result type (might be due to invalid IL or missing references) //IL_020f: Expected O, but got Unknown //IL_01f7: Unknown result type (might be due to invalid IL or missing references) //IL_0201: Expected O, but got Unknown //IL_0221: Unknown result type (might be due to invalid IL or missing references) //IL_0228: Invalid comparison between Unknown and I4 //IL_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_00e4: Invalid comparison between Unknown and I4 //IL_022f: Unknown result type (might be due to invalid IL or missing references) //IL_0236: Invalid comparison between Unknown and I4 //IL_0121: Unknown result type (might be due to invalid IL or missing references) //IL_0128: Expected O, but got Unknown //IL_012a: Unknown result type (might be due to invalid IL or missing references) //IL_012f: Unknown result type (might be due to invalid IL or missing references) Nodes type = node.Type; if ((int)type <= 32) { if ((int)type <= 7) { if ((int)type != 3) { if ((int)type != 7) { return; } BinaryExpression val = (BinaryExpression)node; if (!_preparationOptions.FoldConstants || (int)val.Operator == 19 || (int)val.Operator == 20 || val == null) { return; } Expression left = val.Left; Literal val2 = (Literal)(object)((left is Literal) ? left : null); if (val2 == null) { return; } Expression right = val.Right; Literal val3 = (Literal)(object)((right is Literal) ? right : null); if (val3 == null) { return; } JsValue? jsValue = JintLiteralExpression.ConvertToJsValue(val2); JsValue jsValue2 = JintLiteralExpression.ConvertToJsValue(val3); if ((object)jsValue == null || (object)jsValue2 == null) { return; } try { JintExpression jintExpression = JintBinaryExpression.Build(val); EvaluationContext context = new EvaluationContext(); ((SyntaxElement)node).AssociatedData = new JintConstantExpression((Expression)(object)val, (JsValue)jintExpression.EvaluateWithoutNodeTracking(context)); return; } catch { return; } } } else if (type - 30 > 1) { if ((int)type == 32) { Identifier val4 = (Identifier)node; string name = val4.Name; if (!_bindingNames.TryGetValue(name, out Jint.Runtime.Environments.Environment.BindingName value)) { value = (_bindingNames[name] = new Jint.Runtime.Environments.Environment.BindingName(JsString.CachedCreate(name))); } ((SyntaxElement)node).AssociatedData = new JintIdentifierExpression(val4, value); } return; } IFunction function = (IFunction)node; ((SyntaxElement)node).AssociatedData = JintFunctionDefinition.BuildState(function); } else if ((int)type <= 43) { if ((int)type != 41) { if ((int)type == 43) { ((SyntaxElement)node).AssociatedData = JintMemberExpression.InitializeDeterminedProperty((MemberExpression)node, cache: true); } return; } Literal val5 = (Literal)node; JsValue jsValue3 = JintLiteralExpression.ConvertToJsValue(val5); ((SyntaxElement)node).AssociatedData = (((object)jsValue3 != null) ? new JintConstantExpression((Expression)(object)val5, jsValue3) : null); if (((SyntaxElement)node).AssociatedData != null || (int)val5.TokenType != 9 || _canCompileNegativeLookaroundAssertions || _preparationOptions.ParsingOptions.CompileRegex == false) { return; } RegExpLiteral val6 = (RegExpLiteral)val5; RegExpParseResult parseResult = val6.ParseResult; if (!((RegExpParseResult)(ref parseResult)).Success || !((Literal)val6).Raw.Contains("(?!")) { return; } if (!_regexes.TryGetValue(((Literal)val6).Raw, out Regex value2)) { value2 = ((RegExpParseResult)(ref parseResult)).Regex; if ((value2.Options & RegexOptions.Compiled) != RegexOptions.None) { value2 = new Regex(value2.ToString(), value2.Options & ~RegexOptions.Compiled, value2.MatchTimeout); } _regexes[((Literal)val6).Raw] = value2; } ((SyntaxElement)val6).AssociatedData = value2; } else if ((int)type != 50) { if ((int)type != 54) { if ((int)type == 67) { ((SyntaxElement)node).AssociatedData = JintUnaryExpression.BuildConstantExpression((UnaryExpression)node); } return; } ReturnStatement val7 = (ReturnStatement)node; Expression argument = val7.Argument; Literal val8 = (Literal)(object)((argument is Literal) ? argument : null); if (val8 != null) { JsValue jsValue4 = JintLiteralExpression.ConvertToJsValue(val8); if ((object)jsValue4 != null) { ((SyntaxElement)node).AssociatedData = new ConstantStatement((Statement)(object)val7, CompletionType.Return, jsValue4); } } } else { ((SyntaxElement)node).AssociatedData = new CachedHoistingScope((Program)node); } } static AstAnalyzer() { int? num = typeof(Regex).Assembly.GetName().Version?.Major; bool flag; if (num.HasValue) { int valueOrDefault = num.GetValueOrDefault(); if ((uint)(valueOrDefault - 7) > 1u) { flag = false; goto IL_0050; } } flag = true; goto IL_0050; IL_0050: _canCompileNegativeLookaroundAssertions = !flag; } } public class ConstraintOperations { private readonly Engine _engine; internal ConstraintOperations(Engine engine) { _engine = engine; } public void Check() { Constraint[] constraints = _engine._constraints; for (int i = 0; i < constraints.Length; i++) { constraints[i].Check(); } } public T? Find() where T : Constraint { Constraint[] constraints = _engine._constraints; foreach (Constraint constraint in constraints) { if (constraint.GetType() == typeof(T)) { return (T)constraint; } } return null; } public void Reset() { Constraint[] constraints = _engine._constraints; for (int i = 0; i < constraints.Length; i++) { constraints[i].Reset(); } } } internal readonly record struct ClrPropertyDescriptorFactoriesKey(Type Type, Key PropertyName); [DebuggerDisplay("Engine")] private sealed class EngineDebugView { private readonly Engine _engine; public ObjectInstance Globals => _engine.Realm.GlobalObject; public Options Options => _engine.Options; public Jint.Runtime.Environments.Environment VariableEnvironment => _engine.ExecutionContext.VariableEnvironment; public Jint.Runtime.Environments.Environment LexicalEnvironment => _engine.ExecutionContext.LexicalEnvironment; public EngineDebugView(Engine engine) { _engine = engine; } } public class ModuleOperations { private readonly Engine _engine; private readonly Dictionary _modules = new Dictionary(StringComparer.Ordinal); private readonly Dictionary _builders = new Dictionary(StringComparer.Ordinal); internal IModuleLoader ModuleLoader { get; } public ModuleOperations(Engine engine, IModuleLoader moduleLoader) { ModuleLoader = moduleLoader; _engine = engine; } internal Jint.Runtime.Modules.Module Load(string? referencingModuleLocation, ModuleRequest request) { _ = request.Specifier; ResolvedSpecifier resolvedSpecifier = ModuleLoader.Resolve(referencingModuleLocation, request); if (_modules.TryGetValue(resolvedSpecifier.Key, out Jint.Runtime.Modules.Module value)) { return value; } value = ((!_builders.TryGetValue(resolvedSpecifier.Key, out ModuleBuilder value2)) ? LoadFromModuleLoader(resolvedSpecifier) : LoadFromBuilder(resolvedSpecifier.Key, value2, resolvedSpecifier)); if (value is SourceTextModule sourceTextModule) { _engine.Debugger.OnBeforeEvaluate((Program)(object)sourceTextModule._source); } return value; } private BuilderModule LoadFromBuilder(string specifier, ModuleBuilder moduleBuilder, ResolvedSpecifier moduleResolution) { Prepared source = moduleBuilder.Parse(); BuilderModule builderModule = new BuilderModule(_engine, _engine.Realm, in source, ((SyntaxElement)source.Program).Location.Source, async: false); _modules[moduleResolution.Key] = builderModule; moduleBuilder.BindExportedValues(builderModule); _builders.Remove(specifier); return builderModule; } private Jint.Runtime.Modules.Module LoadFromModuleLoader(ResolvedSpecifier moduleResolution) { Jint.Runtime.Modules.Module module = ModuleLoader.LoadModule(_engine, moduleResolution); _modules[moduleResolution.Key] = module; return module; } public void Add(string specifier, string code) { ModuleBuilder moduleBuilder = new ModuleBuilder(_engine, specifier); moduleBuilder.AddSource(code); Add(specifier, moduleBuilder); } public void Add(string specifier, Action buildModule) { ModuleBuilder moduleBuilder = new ModuleBuilder(_engine, specifier); buildModule(moduleBuilder); Add(specifier, moduleBuilder); } public void Add(string specifier, ModuleBuilder moduleBuilder) { _builders.Add(specifier, moduleBuilder); } public ObjectInstance Import(string specifier) { return Import(specifier, null); } internal ObjectInstance Import(string specifier, string? referencingModuleLocation) { return Import(new ModuleRequest(specifier, Array.Empty()), referencingModuleLocation); } internal ObjectInstance Import(ModuleRequest request, string? referencingModuleLocation) { ResolvedSpecifier resolvedSpecifier = ModuleLoader.Resolve(referencingModuleLocation, request); if (!_modules.TryGetValue(resolvedSpecifier.Key, out Jint.Runtime.Modules.Module value)) { value = Load(referencingModuleLocation, request); } CyclicModule cyclicModule = value as CyclicModule; if ((object)cyclicModule == null) { LinkModule(request.Specifier, value); EvaluateModule(request.Specifier, value); } else if (cyclicModule.Status == ModuleStatus.Unlinked) { LinkModule(request.Specifier, cyclicModule); if (cyclicModule.Status == ModuleStatus.Linked) { _engine.ExecuteWithConstraints(strict: true, () => EvaluateModule(request.Specifier, cyclicModule)); } if (cyclicModule.Status != ModuleStatus.Evaluated) { ExceptionHelper.ThrowNotSupportedException($"Error while evaluating module: Module is in an invalid state: '{cyclicModule.Status}'"); } } _engine.RunAvailableContinuations(); return Jint.Runtime.Modules.Module.GetModuleNamespace(value); } private static void LinkModule(string specifier, Jint.Runtime.Modules.Module module) { module.Link(); } private JsValue EvaluateModule(string specifier, Jint.Runtime.Modules.Module module) { //IL_00bb: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: Unknown result type (might be due to invalid IL or missing references) //IL_00c0: Unknown result type (might be due to invalid IL or missing references) bool flag = _engine._activeEvaluationContext == null; Engine engine = _engine; if (engine._activeEvaluationContext == null) { engine._activeEvaluationContext = new EvaluationContext(_engine); } JsValue jsValue; try { jsValue = module.Evaluate(); } finally { if (flag) { _engine._activeEvaluationContext = null; } } if (!(jsValue is JsPromise jsPromise)) { ExceptionHelper.ThrowInvalidOperationException($"Error while evaluating module: Module evaluation did not return a promise: {jsValue.Type}"); } else if (jsPromise.State == PromiseState.Rejected) { SyntaxElement val = AstExtensions.CreateLocationNode((module is CyclicModule cyclicModule) ? cyclicModule.AbnormalCompletionLocation : Location.From(default(Position), default(Position), (string)null)); ExceptionHelper.ThrowJavaScriptException(_engine, jsPromise.Value, in val.Location); } else if (jsPromise.State != PromiseState.Fulfilled) { ExceptionHelper.ThrowInvalidOperationException($"Error while evaluating module: Module evaluation did not return a fulfilled promise: {jsPromise.State}"); } return jsValue; } } private static readonly Options _defaultEngineOptions = new Options(); private readonly ParserOptions _defaultParserOptions; private readonly JavaScriptParser _defaultParser; private readonly ExecutionContextStack _executionContexts; private JsValue _completionValue = JsValue.Undefined; internal EvaluationContext? _activeEvaluationContext; internal ErrorDispatchInfo? _error; private readonly EventLoop _eventLoop = new EventLoop(); private readonly Agent _agent = new Agent(); private DebugHandler? _debugger; internal readonly IObjectConverter[]? _objectConverters; internal readonly Constraint[] _constraints; internal readonly bool _isDebugMode; internal readonly bool _isStrict; internal readonly IReferenceResolver _referenceResolver; internal readonly ReferencePool _referencePool; internal readonly ArgumentsInstancePool _argumentsInstancePool; internal readonly JsValueArrayPool _jsValueArrayPool; internal readonly ExtensionMethodCache _extensionMethods; internal readonly Dictionary TypeCache = new Dictionary(StringComparer.Ordinal); internal Dictionary? _typeReferences; internal ConditionalWeakTable? _objectWrapperCache; internal readonly JintCallStack CallStack; internal readonly StackGuard _stackGuard; internal Intrinsics _originalIntrinsics; internal Host _host; internal Dictionary _reflectionAccessors = new Dictionary(); internal Realm? _realmInConstruction; internal SyntaxElement? _lastSyntaxElement; internal const bool FoldConstantsOnPrepareByDefault = true; internal static readonly ParserOptions BaseParserOptions; public AdvancedOperations Advanced { get; } public ConstraintOperations Constraints { get; } public ITypeConverter TypeConverter { get; internal set; } internal ref readonly Jint.Runtime.Environments.ExecutionContext ExecutionContext { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return ref _executionContexts.Peek(); } } internal Realm Realm => _realmInConstruction ?? ExecutionContext.Realm; public Intrinsics Intrinsics => Realm.Intrinsics; public ObjectInstance Global => Realm.GlobalObject; internal GlobalSymbolRegistry GlobalSymbolRegistry { get; } = new GlobalSymbolRegistry(); internal long CurrentMemoryUsage { get; private set; } internal Options Options { [MethodImpl(MethodImplOptions.AggressiveInlining)] get; private set; } public DebugHandler Debugger => _debugger ?? (_debugger = new DebugHandler(this, Options.Debugger.InitialStepMode)); public ModuleOperations Modules { get; internal set; } public static Prepared