diff --git a/Jint/Collections/DictionarySlim.cs b/Jint/Collections/DictionarySlim.cs index b25f062ee9..35ec3812f0 100644 --- a/Jint/Collections/DictionarySlim.cs +++ b/Jint/Collections/DictionarySlim.cs @@ -75,8 +75,8 @@ public void Clear() public bool ContainsKey(TKey key) { Entry[] entries = _entries; - for (int i = _buckets[key.GetHashCode() & (_buckets.Length-1)] - 1; - (uint)i < (uint)entries.Length; i = entries[i].next) + for (int i = _buckets[key.GetHashCode() & (_buckets.Length - 1)] - 1; + (uint) i < (uint) entries.Length; i = entries[i].next) { if (key.Equals(entries[i].key)) return true; @@ -89,7 +89,7 @@ public bool TryGetValue(TKey key, out TValue value) { Entry[] entries = _entries; for (int i = _buckets[key.GetHashCode() & (_buckets.Length - 1)] - 1; - (uint)i < (uint)entries.Length; i = entries[i].next) + (uint) i < (uint) entries.Length; i = entries[i].next) { if (key.Equals(entries[i].key)) { @@ -152,7 +152,7 @@ public ref TValue GetOrAddValueRef(TKey key) Entry[] entries = _entries; int bucketIndex = key.GetHashCode() & (_buckets.Length - 1); for (int i = _buckets[bucketIndex] - 1; - (uint)i < (uint)entries.Length; i = entries[i].next) + (uint) i < (uint) entries.Length; i = entries[i].next) { if (key.Equals(entries[i].key)) return ref entries[i].value; @@ -200,7 +200,7 @@ private Entry[] Resize() Debug.Assert(_entries.Length == _count || _entries.Length == 1); // We only copy _count, so if it's longer we will miss some int count = _count; int newSize = _entries.Length * 2; - if ((uint)newSize > (uint)int.MaxValue) // uint cast handles overflow + if ((uint) newSize > int.MaxValue) // uint cast handles overflow throw new InvalidOperationException("Capacity Overflow"); var entries = new Entry[newSize]; diff --git a/Jint/Collections/StringDictionarySlim.cs b/Jint/Collections/StringDictionarySlim.cs index c922f04bea..6a43054a28 100644 --- a/Jint/Collections/StringDictionarySlim.cs +++ b/Jint/Collections/StringDictionarySlim.cs @@ -127,7 +127,7 @@ public override ref TValue GetValueRefOrNullRef(Key key) Entry[] entries = _entries; int bucketIndex = key.HashCode & (_buckets.Length - 1); for (int i = _buckets[bucketIndex] - 1; - (uint)i < (uint)entries.Length; i = entries[i].next) + (uint) i < (uint) entries.Length; i = entries[i].next) { if (key.Name == entries[i].key.Name) { @@ -154,7 +154,7 @@ public override ref TValue GetValueRefOrAddDefault(Key key, out bool exists) Entry[] entries = _entries; int bucketIndex = key.HashCode & (_buckets.Length - 1); for (int i = _buckets[bucketIndex] - 1; - (uint)i < (uint)entries.Length; i = entries[i].next) + (uint) i < (uint) entries.Length; i = entries[i].next) { if (key.Name == entries[i].key.Name) { @@ -172,7 +172,7 @@ public bool TryAdd(Key key, TValue value) Entry[] entries = _entries; int bucketIndex = key.HashCode & (_buckets.Length - 1); for (int i = _buckets[bucketIndex] - 1; - (uint)i < (uint)entries.Length; i = entries[i].next) + (uint) i < (uint) entries.Length; i = entries[i].next) { if (key.Name == entries[i].key.Name) { @@ -226,7 +226,7 @@ private Entry[] Resize() Debug.Assert(_entries.Length == _count || _entries.Length == 1); // We only copy _count, so if it's longer we will miss some int count = _count; int newSize = _entries.Length * 2; - if ((uint)newSize > (uint)int.MaxValue) // uint cast handles overflow + if ((uint) newSize > int.MaxValue) // uint cast handles overflow throw new InvalidOperationException("Capacity Overflow"); var entries = new Entry[newSize]; diff --git a/Jint/Engine.Modules.cs b/Jint/Engine.Modules.cs index c1a7b313d4..d2aaf34f19 100644 --- a/Jint/Engine.Modules.cs +++ b/Jint/Engine.Modules.cs @@ -148,7 +148,7 @@ private static void LinkModule(string specifier, Module module) private JsValue EvaluateModule(string specifier, Module module) { var ownsContext = _engine._activeEvaluationContext is null; - _engine. _activeEvaluationContext ??= new EvaluationContext(_engine); + _engine._activeEvaluationContext ??= new EvaluationContext(_engine); JsValue evaluationResult; try { diff --git a/Jint/Engine.cs b/Jint/Engine.cs index d4839854b0..cd33faa97a 100644 --- a/Jint/Engine.cs +++ b/Jint/Engine.cs @@ -52,7 +52,7 @@ public sealed partial class Engine : IDisposable internal readonly bool _isDebugMode; internal readonly bool _isStrict; - private bool _customResolver; + private readonly bool _customResolver; internal readonly IReferenceResolver _referenceResolver; internal readonly ReferencePool _referencePool; @@ -1608,7 +1608,7 @@ public void Dispose() } #if SUPPORTS_WEAK_TABLE_CLEAR - _objectWrapperCache.Clear(); + _objectWrapperCache.Clear(); #else // we can expect that reflection is OK as we've been generating object wrappers already var clearMethod = _objectWrapperCache.GetType().GetMethod("Clear", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic); diff --git a/Jint/Extensions/Character.cs b/Jint/Extensions/Character.cs index 924b34ba6b..64a8192983 100644 --- a/Jint/Extensions/Character.cs +++ b/Jint/Extensions/Character.cs @@ -10,7 +10,7 @@ internal static class Character public const string AsciiWordCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_"; [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool IsInRange(this char c, ushort min, ushort max) => (uint)(c - min) <= (uint)(max - min); + public static bool IsInRange(this char c, ushort min, ushort max) => (uint) (c - min) <= (uint) (max - min); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsOctalDigit(this char c) => c.IsInRange('0', '7'); diff --git a/Jint/Extensions/Hash.cs b/Jint/Extensions/Hash.cs index dace6edf27..066d51823f 100644 --- a/Jint/Extensions/Hash.cs +++ b/Jint/Extensions/Hash.cs @@ -15,7 +15,7 @@ internal static class Hash /// The offset bias value used in the FNV-1a algorithm /// See http://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function /// - private const int FnvOffsetBias = unchecked((int)2166136261); + private const int FnvOffsetBias = unchecked((int) 2166136261); /// /// The generative factor used in the FNV-1a algorithm @@ -53,10 +53,10 @@ internal static int GetFNVHashCode(System.Text.StringBuilder text) int hashCode = FnvOffsetBias; #if NETCOREAPP3_1_OR_GREATER - foreach (var chunk in text.GetChunks()) - { - hashCode = CombineFNVHash(hashCode, chunk.Span); - } + foreach (var chunk in text.GetChunks()) + { + hashCode = CombineFNVHash(hashCode, chunk.Span); + } #else // StringBuilder.GetChunks is not available in this target framework. Since there is no other direct access // to the underlying storage spans of StringBuilder, we fall back to using slower per-character operations. diff --git a/Jint/Extensions/WebEncoders.cs b/Jint/Extensions/WebEncoders.cs index 45d0b2188f..522099f248 100644 --- a/Jint/Extensions/WebEncoders.cs +++ b/Jint/Extensions/WebEncoders.cs @@ -136,16 +136,16 @@ public static string Base64UrlEncode(byte[] input, int offset, int count, bool o #if NETCOREAPP return Base64UrlEncode(input.AsSpan(offset, count), omitPadding); #else - // Special-case empty input - if (count == 0) - { - return string.Empty; - } + // Special-case empty input + if (count == 0) + { + return string.Empty; + } - var buffer = new char[GetArraySizeRequiredToEncode(count)]; - var numBase64Chars = Base64UrlEncode(input, offset, buffer, outputOffset: 0, count: count, omitPadding); + var buffer = new char[GetArraySizeRequiredToEncode(count)]; + var numBase64Chars = Base64UrlEncode(input, offset, buffer, outputOffset: 0, count: count, omitPadding); - return new string(buffer, startIndex: 0, length: numBase64Chars); + return new string(buffer, startIndex: 0, length: numBase64Chars); #endif } @@ -193,37 +193,37 @@ public static int Base64UrlEncode(byte[] input, int offset, char[] output, int o #if NETCOREAPP return Base64UrlEncode(input.AsSpan(offset, count), output.AsSpan(outputOffset), omitPadding); #else - // Special-case empty input. - if (count == 0) - { - return 0; - } + // Special-case empty input. + if (count == 0) + { + return 0; + } - // Use base64url encoding with no padding characters. See RFC 4648, Sec. 5. + // Use base64url encoding with no padding characters. See RFC 4648, Sec. 5. - // Start with default Base64 encoding. - var numBase64Chars = Convert.ToBase64CharArray(input, offset, count, output, outputOffset); + // Start with default Base64 encoding. + var numBase64Chars = Convert.ToBase64CharArray(input, offset, count, output, outputOffset); - // Fix up '+' -> '-' and '/' -> '_'. Drop padding characters. - for (var i = outputOffset; i - outputOffset < numBase64Chars; i++) + // Fix up '+' -> '-' and '/' -> '_'. Drop padding characters. + for (var i = outputOffset; i - outputOffset < numBase64Chars; i++) + { + var ch = output[i]; + if (ch == '+') + { + output[i] = '-'; + } + else if (ch == '/') { - var ch = output[i]; - if (ch == '+') - { - output[i] = '-'; - } - else if (ch == '/') - { - output[i] = '_'; - } - else if (omitPadding && ch == '=') - { - // We've reached a padding character; truncate the remainder. - return i - outputOffset; - } + output[i] = '_'; } + else if (omitPadding && ch == '=') + { + // We've reached a padding character; truncate the remainder. + return i - outputOffset; + } + } - return numBase64Chars; + return numBase64Chars; #endif } diff --git a/Jint/HoistingScope.cs b/Jint/HoistingScope.cs index 5334c83804..15a10ccdf0 100644 --- a/Jint/HoistingScope.cs +++ b/Jint/HoistingScope.cs @@ -174,7 +174,7 @@ public void Visit(Node node, Node? parent) var childType = childNode.Type; if (childType == NodeType.VariableDeclaration) { - var variableDeclaration = (VariableDeclaration)childNode; + var variableDeclaration = (VariableDeclaration) childNode; if (variableDeclaration.Kind == VariableDeclarationKind.Var) { _variableDeclarations ??= []; @@ -217,7 +217,7 @@ public void Visit(Node node, Node? parent) if (parent is null || (node.Type != NodeType.BlockStatement && node.Type != NodeType.SwitchCase)) { _functions ??= []; - _functions.Add((FunctionDeclaration)childNode); + _functions.Add((FunctionDeclaration) childNode); } } else if (childType == NodeType.ClassDeclaration && parent is null or AstModule) diff --git a/Jint/Jint.csproj b/Jint/Jint.csproj index dc9c3242b0..3e62322506 100644 --- a/Jint/Jint.csproj +++ b/Jint/Jint.csproj @@ -12,7 +12,7 @@ true latest-Recommended - false + true true README.md diff --git a/Jint/Native/Array/ArrayConstructor.cs b/Jint/Native/Array/ArrayConstructor.cs index c281e0478f..49b0612e24 100644 --- a/Jint/Native/Array/ArrayConstructor.cs +++ b/Jint/Native/Array/ArrayConstructor.cs @@ -42,7 +42,7 @@ protected override void Initialize() var symbols = new SymbolDictionary(1) { - [GlobalSymbolRegistry.Species] = new GetSetPropertyDescriptor(get: new ClrFunction(Engine, "get [Symbol.species]", Species, 0, PropertyFlag.Configurable), set: Undefined,PropertyFlag.Configurable), + [GlobalSymbolRegistry.Species] = new GetSetPropertyDescriptor(get: new ClrFunction(Engine, "get [Symbol.species]", Species, 0, PropertyFlag.Configurable), set: Undefined, PropertyFlag.Configurable), }; SetSymbols(symbols); } @@ -202,7 +202,7 @@ private JsValue Of(JsValue thisObject, JsCallArguments arguments) // faster for real arrays for (uint k = 0; k < arguments.Length; k++) { - var kValue = arguments[(int)k]; + var kValue = arguments[(int) k]; ai.SetIndexValue(k, kValue, updateLength: k == arguments.Length - 1); } } @@ -211,7 +211,7 @@ private JsValue Of(JsValue thisObject, JsCallArguments arguments) // slower version for (uint k = 0; k < arguments.Length; k++) { - var kValue = arguments[(int)k]; + var kValue = arguments[(int) k]; var key = JsString.Create(k); a.CreateDataPropertyOrThrow(key, kValue); } diff --git a/Jint/Native/Array/ArrayIteratorPrototype.cs b/Jint/Native/Array/ArrayIteratorPrototype.cs index 696b212a84..543fcd607f 100644 --- a/Jint/Native/Array/ArrayIteratorPrototype.cs +++ b/Jint/Native/Array/ArrayIteratorPrototype.cs @@ -47,7 +47,7 @@ internal IteratorInstance Construct(ObjectInstance array, ArrayIteratorType kind } IteratorInstance instance = array is JsArray jsArray - ? new ArrayIterator(Engine, jsArray, kind) { _prototype = this } + ? new ArrayIterator(Engine, jsArray, kind) { _prototype = this } : new ArrayLikeIterator(Engine, array, kind) { _prototype = this }; return instance; diff --git a/Jint/Native/Array/ArrayOperations.cs b/Jint/Native/Array/ArrayOperations.cs index e9131b3850..e7a1f51017 100644 --- a/Jint/Native/Array/ArrayOperations.cs +++ b/Jint/Native/Array/ArrayOperations.cs @@ -602,7 +602,7 @@ public override void SetLength(ulong length) public override void EnsureCapacity(ulong capacity) { - _target.EnsureCapacity((int)capacity); + _target.EnsureCapacity((int) capacity); } public override JsValue Get(ulong index) => index < (ulong) _target.Length ? ReadValue((int) index) : JsValue.Undefined; @@ -631,7 +631,7 @@ public override void CreateDataPropertyOrThrow(ulong index, JsValue value) public override void Set(ulong index, JsValue value, bool updateLength = false, bool throwOnError = true) { - _target.SetAt((int)index, value); + _target.SetAt((int) index, value); } public override void DeletePropertyOrThrow(ulong index) diff --git a/Jint/Native/Array/ArrayPrototype.cs b/Jint/Native/Array/ArrayPrototype.cs index 34fe0a0686..838ef0796f 100644 --- a/Jint/Native/Array/ArrayPrototype.cs +++ b/Jint/Native/Array/ArrayPrototype.cs @@ -69,7 +69,7 @@ protected override void Initialize() ["reduce"] = new LazyPropertyDescriptor(this, static prototype => new ClrFunction(prototype._engine, "reduce", prototype.Reduce, 1, PropertyFlag.Configurable), PropertyFlags), ["reduceRight"] = new LazyPropertyDescriptor(this, static prototype => new ClrFunction(prototype._engine, "reduceRight", prototype.ReduceRight, 1, PropertyFlag.Configurable), PropertyFlags), ["reverse"] = new LazyPropertyDescriptor(this, static prototype => new ClrFunction(prototype._engine, "reverse", prototype.Reverse, 0, PropertyFlag.Configurable), PropertyFlags), - ["shift"] = new LazyPropertyDescriptor(this, static prototype => new ClrFunction(prototype._engine, "shift",prototype. Shift, 0, PropertyFlag.Configurable), PropertyFlags), + ["shift"] = new LazyPropertyDescriptor(this, static prototype => new ClrFunction(prototype._engine, "shift", prototype.Shift, 0, PropertyFlag.Configurable), PropertyFlags), ["slice"] = new LazyPropertyDescriptor(this, static prototype => new ClrFunction(prototype._engine, "slice", prototype.Slice, 2, PropertyFlag.Configurable), PropertyFlags), ["some"] = new LazyPropertyDescriptor(this, static prototype => new ClrFunction(prototype._engine, "some", prototype.Some, 1, PropertyFlag.Configurable), PropertyFlags), ["sort"] = new LazyPropertyDescriptor(this, static prototype => new ClrFunction(prototype._engine, "sort", prototype.Sort, 1, PropertyFlag.Configurable), PropertyFlags), @@ -1093,11 +1093,13 @@ private JsValue Sort(JsValue thisObject, JsCallArguments arguments) ordered = items.OrderBy(x => x, comparer); } #else - #if NET8_0_OR_GREATER - ordered = items.Order(comparer); - #else - ordered = items.OrderBy(x => x, comparer); - #endif + +#if NET8_0_OR_GREATER + ordered = items.Order(comparer); +#else + ordered = items.OrderBy(x => x, comparer); +#endif + #endif uint j = 0; foreach (var item in ordered) diff --git a/Jint/Native/ArrayBuffer/ArrayBufferConstructor.cs b/Jint/Native/ArrayBuffer/ArrayBufferConstructor.cs index f279214b1e..9666b8249a 100644 --- a/Jint/Native/ArrayBuffer/ArrayBufferConstructor.cs +++ b/Jint/Native/ArrayBuffer/ArrayBufferConstructor.cs @@ -40,7 +40,7 @@ protected override void Initialize() var symbols = new SymbolDictionary(1) { - [GlobalSymbolRegistry.Species] = new GetSetPropertyDescriptor(get: new ClrFunction(Engine, "get [Symbol.species]", Species, 0, lengthFlags), set: Undefined,PropertyFlag.Configurable), + [GlobalSymbolRegistry.Species] = new GetSetPropertyDescriptor(get: new ClrFunction(Engine, "get [Symbol.species]", Species, 0, lengthFlags), set: Undefined, PropertyFlag.Configurable), }; SetSymbols(symbols); } diff --git a/Jint/Native/Date/DateConstructor.cs b/Jint/Native/Date/DateConstructor.cs index 5d6c5cdb2d..d73039994d 100644 --- a/Jint/Native/Date/DateConstructor.cs +++ b/Jint/Native/Date/DateConstructor.cs @@ -87,7 +87,7 @@ private static JsValue Utc(JsValue thisObject, JsCallArguments arguments) var yInteger = TypeConverter.ToInteger(y); if (!double.IsNaN(y) && 0 <= yInteger && yInteger <= 99) { - y = yInteger + 1900; + y = yInteger + 1900; } var finalDate = DatePrototype.MakeDate( diff --git a/Jint/Native/Date/DatePrototype.cs b/Jint/Native/Date/DatePrototype.cs index 5c3e98b4bf..6a97971234 100644 --- a/Jint/Native/Date/DatePrototype.cs +++ b/Jint/Native/Date/DatePrototype.cs @@ -36,7 +36,7 @@ internal DatePrototype( _timeSystem = engine.Options.TimeSystem; } - protected override void Initialize() + protected override void Initialize() { const PropertyFlag lengthFlags = PropertyFlag.Configurable; const PropertyFlag propertyFlags = PropertyFlag.Configurable | PropertyFlag.Writable; @@ -122,7 +122,7 @@ private JsValue ToPrimitive(JsValue thisObject, JsCallArguments arguments) { tryFirst = Types.String; } - else if (string.Equals(hintString, "number", StringComparison.Ordinal)) + else if (string.Equals(hintString, "number", StringComparison.Ordinal)) { tryFirst = Types.Number; } @@ -447,7 +447,7 @@ private JsValue GetTimezoneOffset(JsValue thisObject, JsCallArguments arguments) { return JsNumber.DoubleNaN; } - return (int) ((double) t.Value - LocalTime(t).Value)/MsPerMinute; + return (int) ((double) t.Value - LocalTime(t).Value) / MsPerMinute; } /// @@ -873,22 +873,22 @@ private static long TimeWithinDay(DatePresentation t) /// private static int DaysInYear(double y) { - if (y%4 != 0) + if (y % 4 != 0) { return 365; } - if (y%4 == 0 && y%100 != 0) + if (y % 4 == 0 && y % 100 != 0) { return 366; } - if (y%100 == 0 && y%400 != 0) + if (y % 100 == 0 && y % 400 != 0) { return 365; } - if (y%400 == 0) + if (y % 400 == 0) { return 366; } @@ -901,10 +901,10 @@ private static int DaysInYear(double y) /// private static int DayFromYear(DatePresentation y) { - return (int) (365*(y.Value - 1970) - + System.Math.Floor((y.Value - 1969)/4d) - - System.Math.Floor((y.Value - 1901)/100d) - + System.Math.Floor((y.Value - 1601)/400d)); + return (int) (365 * (y.Value - 1970) + + System.Math.Floor((y.Value - 1969) / 4d) + - System.Math.Floor((y.Value - 1901) / 100d) + + System.Math.Floor((y.Value - 1601) / 400d)); } /// @@ -912,7 +912,7 @@ private static int DayFromYear(DatePresentation y) /// private static long TimeFromYear(DatePresentation y) { - return MsPerDay*DayFromYear(y); + return MsPerDay * DayFromYear(y); } /// @@ -1032,7 +1032,7 @@ private static int DateFromTime(DatePresentation t) return dayWithinYear + 1; } - if (monthFromTime== 1) + if (monthFromTime == 1) { return dayWithinYear - 30; } @@ -1185,7 +1185,7 @@ internal static double MakeTime(double hour, double min, double sec, double ms) var m = TypeConverter.ToInteger(min); var s = TypeConverter.ToInteger(sec); var milli = TypeConverter.ToInteger(ms); - var t = h*MsPerHour + m*MsPerMinute + s*MsPerSecond + milli; + var t = h * MsPerHour + m * MsPerMinute + s * MsPerSecond + milli; return t; } @@ -1262,7 +1262,7 @@ private static bool AreFinite(double value1, double value2, double value3) => IsFinite(value1) && IsFinite(value2) && IsFinite(value3); private static bool AreFinite(double value1, double value2, double value3, double value4) - => IsFinite(value1) && IsFinite(value2) && IsFinite(value3) && IsFinite(value4); + => IsFinite(value1) && IsFinite(value2) && IsFinite(value3) && IsFinite(value4); [StructLayout(LayoutKind.Auto)] private readonly record struct Date(int Year, int Month, int Day); diff --git a/Jint/Native/Function/FunctionInstance.Dynamic.cs b/Jint/Native/Function/FunctionInstance.Dynamic.cs index d5a55f3082..882f99ff6e 100644 --- a/Jint/Native/Function/FunctionInstance.Dynamic.cs +++ b/Jint/Native/Function/FunctionInstance.Dynamic.cs @@ -199,6 +199,10 @@ internal ScriptFunction OrdinaryFunctionCreate( function, scope, thisMode, - functionPrototype) { _privateEnvironment = privateScope, _realm = _realm }; + functionPrototype) + { + _privateEnvironment = privateScope, + _realm = _realm, + }; } } diff --git a/Jint/Native/Global/GlobalObject.cs b/Jint/Native/Global/GlobalObject.cs index 304638f6b2..2e832be327 100644 --- a/Jint/Native/Global/GlobalObject.cs +++ b/Jint/Native/Global/GlobalObject.cs @@ -113,7 +113,7 @@ internal static JsValue ParseInt(JsValue thisObject, JsCallArguments arguments) pow *= radix; } - return hasResult ? JsNumber.Create(sign * result) : JsNumber.DoubleNaN; + return hasResult ? JsNumber.Create(sign * result) : JsNumber.DoubleNaN; } /// @@ -223,7 +223,7 @@ internal static JsValue ParseFloat(JsValue thisObject, JsCallArguments arguments // we should now have proper input part #if SUPPORTS_SPAN_PARSE - var substring = trimmedString.AsSpan(0, i); + var substring = trimmedString.AsSpan(0, i); #else var substring = trimmedString.Substring(0, i); #endif @@ -389,7 +389,7 @@ private JsValue Encode(string uriString, SearchValues allowedCharacters) return builder.ToString(); - uriError: +uriError: _engine.SignalError(ExceptionHelper.CreateUriError(_realm, "URI malformed")); return JsEmpty.Instance; } @@ -448,7 +448,7 @@ private JsValue Decode(string uriString, SearchValues? reservedSet) k += 2; if ((B & 0x80) == 0) { - C = (char)B; + C = (char) B; #pragma warning disable CA2249 if (reservedSet == null || !reservedSet.Contains(C)) #pragma warning restore CA2249 @@ -508,7 +508,7 @@ private JsValue Decode(string uriString, SearchValues? reservedSet) } #if SUPPORTS_SPAN_PARSE - _stringBuilder.Append(Encoding.UTF8.GetString(octets.Slice(0, n))); + _stringBuilder.Append(Encoding.UTF8.GetString(octets.Slice(0, n))); #else _stringBuilder.Append(Encoding.UTF8.GetString(octets, 0, n)); #endif @@ -518,7 +518,7 @@ private JsValue Decode(string uriString, SearchValues? reservedSet) return _stringBuilder.ToString(); - uriError: +uriError: _engine.SignalError(ExceptionHelper.CreateUriError(_realm, "URI malformed")); return JsEmpty.Instance; } @@ -555,15 +555,15 @@ private static byte StringToIntBase16(ReadOnlySpan s) private static bool IsDigit(char c, int radix, out int result) { int tmp; - if ((uint)(c - '0') <= 9) + if ((uint) (c - '0') <= 9) { result = tmp = c - '0'; } - else if ((uint)(c - 'A') <= 'Z' - 'A') + else if ((uint) (c - 'A') <= 'Z' - 'A') { result = tmp = c - 'A' + 10; } - else if ((uint)(c - 'a') <= 'z' - 'a') + else if ((uint) (c - 'a') <= 'z' - 'a') { result = tmp = c - 'a' + 10; } diff --git a/Jint/Native/Intl/IntlInstance.cs b/Jint/Native/Intl/IntlInstance.cs index 5a6b3cbcb9..d8f60823a5 100644 --- a/Jint/Native/Intl/IntlInstance.cs +++ b/Jint/Native/Intl/IntlInstance.cs @@ -38,7 +38,7 @@ protected override void Initialize() ["PluralRules"] = new(_realm.Intrinsics.PluralRules, false, false, true), ["RelativeTimeFormat"] = new(_realm.Intrinsics.RelativeTimeFormat, false, false, true), ["Segmenter"] = new(_realm.Intrinsics.Segmenter, false, false, true), - ["getCanonicalLocales "] = new(new ClrFunction(Engine, "getCanonicalLocales ", GetCanonicalLocales , 1, PropertyFlag.Configurable), true, false, true), + ["getCanonicalLocales "] = new(new ClrFunction(Engine, "getCanonicalLocales ", GetCanonicalLocales, 1, PropertyFlag.Configurable), true, false, true), }; SetProperties(properties); diff --git a/Jint/Native/JsArrayBuffer.cs b/Jint/Native/JsArrayBuffer.cs index 5c19cf3222..d93f04a08f 100644 --- a/Jint/Native/JsArrayBuffer.cs +++ b/Jint/Native/JsArrayBuffer.cs @@ -268,7 +268,7 @@ private byte[] NumericToRawBytes(TypedArrayElementType type, TypedArrayValue val else { // inlined conversion for faster speed instead of getting the method in spec - var doubleValue = value.DoubleValue; + var doubleValue = value.DoubleValue; var intValue = double.IsNaN(doubleValue) || doubleValue == 0 || double.IsInfinity(doubleValue) ? 0 : (long) doubleValue; @@ -289,28 +289,28 @@ private byte[] NumericToRawBytes(TypedArrayElementType type, TypedArrayValue val #if !NETSTANDARD2_1 rawBytes = BitConverter.GetBytes((short) intValue); #else - BitConverter.TryWriteBytes(rawBytes, (short) intValue); + BitConverter.TryWriteBytes(rawBytes, (short) intValue); #endif break; case TypedArrayElementType.Uint16: #if !NETSTANDARD2_1 rawBytes = BitConverter.GetBytes((ushort) intValue); #else - BitConverter.TryWriteBytes(rawBytes, (ushort) intValue); + BitConverter.TryWriteBytes(rawBytes, (ushort) intValue); #endif break; case TypedArrayElementType.Int32: #if !NETSTANDARD2_1 rawBytes = BitConverter.GetBytes((uint) intValue); #else - BitConverter.TryWriteBytes(rawBytes, (uint) intValue); + BitConverter.TryWriteBytes(rawBytes, (uint) intValue); #endif break; case TypedArrayElementType.Uint32: #if !NETSTANDARD2_1 rawBytes = BitConverter.GetBytes((uint) intValue); #else - BitConverter.TryWriteBytes(rawBytes, (uint) intValue); + BitConverter.TryWriteBytes(rawBytes, (uint) intValue); #endif break; default: diff --git a/Jint/Native/JsNumber.cs b/Jint/Native/JsNumber.cs index bc4af32b2d..b075dbb512 100644 --- a/Jint/Native/JsNumber.cs +++ b/Jint/Native/JsNumber.cs @@ -128,7 +128,7 @@ private static JsNumber CreateNumberUnlikely(double value) return DoubleNegativeInfinity; } - if (double.IsPositiveInfinity(value )) + if (double.IsPositiveInfinity(value)) { return DoublePositiveInfinity; } diff --git a/Jint/Native/JsString.cs b/Jint/Native/JsString.cs index 326efb99d3..b636f796f9 100644 --- a/Jint/Native/JsString.cs +++ b/Jint/Native/JsString.cs @@ -37,7 +37,7 @@ public class JsString : JsValue, IEquatable, IEquatable [DebuggerBrowsable(DebuggerBrowsableState.Never)] internal string _value; - private static ConcurrentDictionary _stringCache; + private static readonly ConcurrentDictionary _stringCache; static JsString() { diff --git a/Jint/Native/JsValue.cs b/Jint/Native/JsValue.cs index 0fd1581967..5ec5a43230 100644 --- a/Jint/Native/JsValue.cs +++ b/Jint/Native/JsValue.cs @@ -127,17 +127,17 @@ internal static JsValue ConvertAwaitableToPromise(Engine engine, object obj) } #if NETSTANDARD2_1_OR_GREATER || NETCOREAPP - if (obj is ValueTask valueTask) - { - return ConvertTaskToPromise(engine, valueTask.AsTask()); - } + if (obj is ValueTask valueTask) + { + return ConvertTaskToPromise(engine, valueTask.AsTask()); + } - // ValueTask - var asTask = obj.GetType().GetMethod(nameof(ValueTask.AsTask)); - if (asTask is not null) - { - return ConvertTaskToPromise(engine, (Task) asTask.Invoke(obj, parameters: null)!); - } + // ValueTask + var asTask = obj.GetType().GetMethod(nameof(ValueTask.AsTask)); + if (asTask is not null) + { + return ConvertTaskToPromise(engine, (Task) asTask.Invoke(obj, parameters: null)!); + } #endif return FromObject(engine, JsValue.Undefined); diff --git a/Jint/Native/JsWeakMap.cs b/Jint/Native/JsWeakMap.cs index b05902fff9..c4063f5fd5 100644 --- a/Jint/Native/JsWeakMap.cs +++ b/Jint/Native/JsWeakMap.cs @@ -31,7 +31,7 @@ internal void WeakMapSet(JsValue key, JsValue value) } #if SUPPORTS_WEAK_TABLE_ADD_OR_UPDATE - _table.AddOrUpdate(key, value); + _table.AddOrUpdate(key, value); #else _table.Remove(key); _table.Add(key, value); diff --git a/Jint/Native/Json/JsonSerializer.cs b/Jint/Native/Json/JsonSerializer.cs index bf6ea4fb25..35726f148d 100644 --- a/Jint/Native/Json/JsonSerializer.cs +++ b/Jint/Native/Json/JsonSerializer.cs @@ -318,37 +318,37 @@ private static unsafe void QuoteJSONString(string value, ref ValueStringBuilder json.Append('"'); #if NETCOREAPP1_0_OR_GREATER - fixed (char* ptr = value) + fixed (char* ptr = value) + { + int remainingLength = value.Length; + int offset = 0; + while (true) { - int remainingLength = value.Length; - int offset = 0; - while (true) + int index = System.Text.Encodings.Web.JavaScriptEncoder.Default.FindFirstCharacterToEncode(ptr + offset, remainingLength); + if (index < 0) { - int index = System.Text.Encodings.Web.JavaScriptEncoder.Default.FindFirstCharacterToEncode(ptr + offset, remainingLength); - if (index < 0) - { - // append the remaining text which doesn't need any encoding. - json.Append(value.AsSpan(offset)); - break; - } + // append the remaining text which doesn't need any encoding. + json.Append(value.AsSpan(offset)); + break; + } - index += offset; - if (index - offset > 0) - { - // append everything which does not need any encoding until the found index. - json.Append(value.AsSpan(offset, index - offset)); - } + index += offset; + if (index - offset > 0) + { + // append everything which does not need any encoding until the found index. + json.Append(value.AsSpan(offset, index - offset)); + } - AppendJsonStringCharacter(value, ref index, ref json); + AppendJsonStringCharacter(value, ref index, ref json); - offset = index + 1; - remainingLength = value.Length - offset; - if (remainingLength == 0) - { - break; - } + offset = index + 1; + remainingLength = value.Length - offset; + if (remainingLength == 0) + { + break; } } + } #else for (var i = 0; i < value.Length; i++) { @@ -389,8 +389,8 @@ private static void AppendJsonStringCharacter(string value, ref int index, ref V if (char.IsSurrogatePair(value, index)) { #if NETCOREAPP1_0_OR_GREATER - json.Append(value.AsSpan(index, 2)); - index++; + json.Append(value.AsSpan(index, 2)); + index++; #else json.Append(c); index++; diff --git a/Jint/Native/Math/MathInstance.cs b/Jint/Native/Math/MathInstance.cs index 04376ef8e9..027b1febe6 100644 --- a/Jint/Native/Math/MathInstance.cs +++ b/Jint/Native/Math/MathInstance.cs @@ -203,7 +203,7 @@ private static JsValue Atan2(JsValue thisObject, JsCallArguments arguments) if (y > 0 && x.Equals(0)) { - return System.Math.PI/2; + return System.Math.PI / 2; } if (NumberInstance.IsPositiveZero(y)) @@ -264,7 +264,7 @@ private static JsValue Atan2(JsValue thisObject, JsCallArguments arguments) // If y<0 and x is −0, the result is an implementation-dependent approximation to −π/2. if (y < 0 && x.Equals(0)) { - return -System.Math.PI/2; + return -System.Math.PI / 2; } // If y>0 and y is finite and x is +∞, the result is +0. @@ -302,7 +302,7 @@ private static JsValue Atan2(JsValue thisObject, JsCallArguments arguments) // If y is +∞ and x is finite, the result is an implementation-dependent approximation to +π/2. if (double.IsPositiveInfinity(y) && !double.IsInfinity(x)) { - return System.Math.PI/2; + return System.Math.PI / 2; } // If y is −∞ and x is finite, the result is an implementation-dependent approximation to −π/2. @@ -314,7 +314,7 @@ private static JsValue Atan2(JsValue thisObject, JsCallArguments arguments) // If y is +∞ and x is +∞, the result is an implementation-dependent approximation to +π/4. if (double.IsPositiveInfinity(y) && double.IsPositiveInfinity(x)) { - return System.Math.PI/4; + return System.Math.PI / 4; } // If y is +∞ and x is −∞, the result is an implementation-dependent approximation to +3π/4. @@ -332,7 +332,7 @@ private static JsValue Atan2(JsValue thisObject, JsCallArguments arguments) // If y is −∞ and x is −∞, the result is an implementation-dependent approximation to −3π/4. if (double.IsNegativeInfinity(y) && double.IsNegativeInfinity(x)) { - return - 3 * System.Math.PI / 4; + return -3 * System.Math.PI / 4; } return System.Math.Atan2(y, x); @@ -820,7 +820,7 @@ private static JsValue HandlePowUnlikely(double y, double x) private JsValue Random(JsValue thisObject, JsCallArguments arguments) { - if(_random == null) + if (_random == null) { _random = new Random(); } @@ -853,20 +853,20 @@ private static JsValue Fround(JsValue thisObject, JsCallArguments arguments) private static JsValue F16Round(JsValue thisObject, JsCallArguments arguments) { #if SUPPORTS_HALF - var x = arguments.At(0); - var n = TypeConverter.ToNumber(x); + var x = arguments.At(0); + var n = TypeConverter.ToNumber(x); - if (double.IsNaN(n)) - { - return JsNumber.DoubleNaN; - } + if (double.IsNaN(n)) + { + return JsNumber.DoubleNaN; + } - if (double.IsInfinity(n) || NumberInstance.IsPositiveZero(n) || NumberInstance.IsNegativeZero(n)) - { - return x; - } + if (double.IsInfinity(n) || NumberInstance.IsPositiveZero(n) || NumberInstance.IsNegativeZero(n)) + { + return x; + } - return (double) (Half) n; + return (double) (Half) n; #else ExceptionHelper.ThrowNotImplementedException("Float16/Half type is not supported in this build"); return default; @@ -1020,7 +1020,7 @@ private static JsValue Cbrt(JsValue thisObject, JsCallArguments arguments) if (System.Math.Sign(x) >= 0) { - return System.Math.Pow(x, 1.0/3.0); + return System.Math.Pow(x, 1.0 / 3.0); } return -1 * System.Math.Pow(System.Math.Abs(x), 1.0 / 3.0); @@ -1128,7 +1128,7 @@ private JsValue SumPrecise(JsValue thisObject, JsCallArguments arguments) state = double.NegativeInfinity; } } - else if (!NumberInstance.IsNegativeZero(n) && (NumberInstance.IsNegativeZero(state) || state == Finite)) + else if (!NumberInstance.IsNegativeZero(n) && (NumberInstance.IsNegativeZero(state) || state == Finite)) { state = Finite; sum.Add(n); diff --git a/Jint/Native/Number/Dtoa/BignumDtoa.cs b/Jint/Native/Number/Dtoa/BignumDtoa.cs index dafeacaeab..5bc625a4fd 100644 --- a/Jint/Native/Number/Dtoa/BignumDtoa.cs +++ b/Jint/Native/Number/Dtoa/BignumDtoa.cs @@ -11,7 +11,7 @@ public static void NumberToString( double v, DtoaMode mode, int requested_digits, - ref DtoaBuilder builder, + ref DtoaBuilder builder, out int decimal_point) { var bits = (ulong) BitConverter.DoubleToInt64Bits(v); @@ -117,7 +117,7 @@ private static void GenerateShortestDigits( Bignum delta_minus, Bignum delta_plus, bool is_even, - ref DtoaBuilder buffer) + ref DtoaBuilder buffer) { // Small optimization: if delta_minus and delta_plus are the same just reuse // one of the two bignums. @@ -239,7 +239,7 @@ static void GenerateCountedDigits( ref int decimal_point, Bignum numerator, Bignum denominator, - ref DtoaBuilder buffer) + ref DtoaBuilder buffer) { Debug.Assert(count >= 0); for (int i = 0; i < count - 1; ++i) @@ -286,7 +286,7 @@ static void BignumToFixed( ref int decimal_point, Bignum numerator, Bignum denominator, - ref DtoaBuilder buffer) + ref DtoaBuilder buffer) { // Note that we have to look at more than just the requested_digits, since // a number could be rounded up. Example: v=0.5 with requested_digits=0. diff --git a/Jint/Native/Number/Dtoa/CachePowers.cs b/Jint/Native/Number/Dtoa/CachePowers.cs index abacbfaba9..17a95e93cb 100644 --- a/Jint/Native/Number/Dtoa/CachePowers.cs +++ b/Jint/Native/Number/Dtoa/CachePowers.cs @@ -47,7 +47,7 @@ private sealed class CachedPower internal CachedPower(ulong significand, short binaryExponent, short decimalExponent) { - Significand = significand; + Significand = significand; BinaryExponent = binaryExponent; DecimalExponent = decimalExponent; } diff --git a/Jint/Native/Number/Dtoa/DiyFp.cs b/Jint/Native/Number/Dtoa/DiyFp.cs index 2ff961d258..c76da83795 100644 --- a/Jint/Native/Number/Dtoa/DiyFp.cs +++ b/Jint/Native/Number/Dtoa/DiyFp.cs @@ -79,10 +79,10 @@ internal static DiyFp Times(in DiyFp a, in DiyFp b) ulong b1 = a.F & kM32; ulong c = b.F >> 32; ulong d = b.F & kM32; - ulong ac = a1*c; - ulong bc = b1*c; - ulong ad = a1*d; - ulong bd = b1*d; + ulong ac = a1 * c; + ulong bc = b1 * c; + ulong ad = a1 * d; + ulong bd = b1 * d; ulong tmp = (bd >> 32) + (ad & kM32) + (bc & kM32); // By adding 1U << 31 to tmp we round the final result. // Halfway cases will be round up. diff --git a/Jint/Native/Number/Dtoa/DtoaNumberFormatter.cs b/Jint/Native/Number/Dtoa/DtoaNumberFormatter.cs index ccf8645836..76062401b5 100644 --- a/Jint/Native/Number/Dtoa/DtoaNumberFormatter.cs +++ b/Jint/Native/Number/Dtoa/DtoaNumberFormatter.cs @@ -8,7 +8,7 @@ namespace Jint.Native.Number.Dtoa; internal static class DtoaNumberFormatter { public static void DoubleToAscii( - ref DtoaBuilder buffer, + ref DtoaBuilder buffer, double v, DtoaMode mode, int requested_digits, @@ -42,7 +42,8 @@ public static void DoubleToAscii( } bool fast_worked = false; - switch (mode) { + switch (mode) + { case DtoaMode.Shortest: fast_worked = FastDtoa.NumberToString(v, DtoaMode.Shortest, 0, out point, ref buffer); break; diff --git a/Jint/Native/Number/Dtoa/FastDtoa.cs b/Jint/Native/Number/Dtoa/FastDtoa.cs index 9388be927a..ea90740381 100644 --- a/Jint/Native/Number/Dtoa/FastDtoa.cs +++ b/Jint/Native/Number/Dtoa/FastDtoa.cs @@ -64,7 +64,7 @@ internal sealed class FastDtoa // representable number to the input. // Modifies the generated digits in the buffer to approach (round towards) w. private static bool RoundWeed( - ref DtoaBuilder buffer, + ref DtoaBuilder buffer, ulong distanceTooHighW, ulong unsafeInterval, ulong rest, @@ -167,7 +167,7 @@ private static bool RoundWeed( // Since too_low = too_high - unsafe_interval this is equivalent to // [too_high - unsafe_interval + 4 ulp; too_high - 2 ulp] // Conceptually we have: rest ~= too_high - buffer - return (2*unit <= rest) && (rest <= unsafeInterval - 4*unit); + return (2 * unit <= rest) && (rest <= unsafeInterval - 4 * unit); } // Rounds the buffer upwards if the result is closer to v by possibly adding @@ -183,7 +183,7 @@ private static bool RoundWeed( // // Precondition: rest < ten_kappa. static bool RoundWeedCounted( - ref DtoaBuilder buffer, + ref DtoaBuilder buffer, ulong rest, ulong ten_kappa, ulong unit, @@ -413,7 +413,7 @@ private static bool DigitGen( in DiyFp low, in DiyFp w, in DiyFp high, - ref DtoaBuilder buffer, + ref DtoaBuilder buffer, int mk, out int kappa) { @@ -459,7 +459,7 @@ private static bool DigitGen( // that is smaller than integrals. while (kappa > 0) { - int digit = (int) (integrals/divider); + int digit = (int) (integrals / divider); buffer.Append((char) ('0' + digit)); integrals %= divider; kappa--; @@ -501,7 +501,7 @@ private static bool DigitGen( { fractionals *= 5; unit *= 5; - unsafeInterval = new DiyFp(unsafeInterval.F*5, unsafeInterval.E + 1); // Will be optimized out. + unsafeInterval = new DiyFp(unsafeInterval.F * 5, unsafeInterval.E + 1); // Will be optimized out. one = new DiyFp(one.F.UnsignedShift(1), one.E + 1); // Integer division by one. var digit = (int) ((fractionals.UnsignedShift(-one.E)) & 0xffffffffL); @@ -512,7 +512,7 @@ private static bool DigitGen( { return RoundWeed( ref buffer, - DiyFp.Minus(tooHigh, w).F*unit, + DiyFp.Minus(tooHigh, w).F * unit, unsafeInterval.F, fractionals, one.F, @@ -552,7 +552,7 @@ private static bool DigitGen( static bool DigitGenCounted( in DiyFp w, int requested_digits, - ref DtoaBuilder buffer, + ref DtoaBuilder buffer, out int kappa) { Debug.Assert(MinimalTargetExponent <= w.E && w.E <= MaximalTargetExponent); @@ -592,7 +592,7 @@ static bool DigitGenCounted( if (requested_digits == 0) { ulong rest = (((ulong) integrals) << -one.E) + fractionals; - return RoundWeedCounted(ref buffer, rest,(ulong) divisor << -one.E, w_error, ref kappa); + return RoundWeedCounted(ref buffer, rest, (ulong) divisor << -one.E, w_error, ref kappa); } // The integrals have been generated. We are at the point of the decimal @@ -604,7 +604,8 @@ static bool DigitGenCounted( Debug.Assert(one.E >= -60); Debug.Assert(fractionals < one.F); - while (requested_digits > 0 && fractionals > w_error) { + while (requested_digits > 0 && fractionals > w_error) + { fractionals *= 10; w_error *= 10; // Integer division by one. @@ -629,7 +630,7 @@ static bool DigitGenCounted( // The last digit will be closest to the actual v. That is, even if several // digits might correctly yield 'v' when read again, the closest will be // computed. - private static bool Grisu3(double v, ref DtoaBuilder buffer, out int decimal_exponent) + private static bool Grisu3(double v, ref DtoaBuilder buffer, out int decimal_exponent) { ulong bits = (ulong) BitConverter.DoubleToInt64Bits(v); DiyFp w = DoubleHelper.AsNormalizedDiyFp(bits); @@ -695,7 +696,7 @@ private static bool Grisu3(double v, ref DtoaBuilder buffer, out int decimal_ex static bool Grisu3Counted( double v, int requested_digits, - ref DtoaBuilder buffer, + ref DtoaBuilder buffer, out int decimal_exponent) { ulong bits = (ulong) BitConverter.DoubleToInt64Bits(v); @@ -735,7 +736,7 @@ public static bool NumberToString( DtoaMode mode, int requested_digits, out int decimal_point, - ref DtoaBuilder buffer) + ref DtoaBuilder buffer) { Debug.Assert(v > 0); Debug.Assert(!double.IsNaN(v)); diff --git a/Jint/Native/Number/Dtoa/NumberExtensions.cs b/Jint/Native/Number/Dtoa/NumberExtensions.cs index 21ae514408..770ccec6da 100644 --- a/Jint/Native/Number/Dtoa/NumberExtensions.cs +++ b/Jint/Native/Number/Dtoa/NumberExtensions.cs @@ -9,7 +9,7 @@ internal static long UnsignedShift(this long l, int shift) { return (long) ((ulong) l >> shift); } - + [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static ulong UnsignedShift(this ulong l, int shift) { diff --git a/Jint/Native/Number/NumberPrototype.cs b/Jint/Native/Number/NumberPrototype.cs index ca676475ae..f38fa5a52d 100644 --- a/Jint/Native/Number/NumberPrototype.cs +++ b/Jint/Native/Number/NumberPrototype.cs @@ -233,7 +233,7 @@ private JsValue ToExponential(JsValue thisObject, JsCallArguments arguments) Debug.Assert(dtoaBuilder.Length <= f + 1); int exponent = decimalPoint - 1; - var result = CreateExponentialRepresentation(ref dtoaBuilder, exponent, negative, f+1); + var result = CreateExponentialRepresentation(ref dtoaBuilder, exponent, negative, f + 1); return result; } @@ -324,7 +324,7 @@ private JsValue ToPrecision(JsValue thisObject, JsCallArguments arguments) } private static string CreateExponentialRepresentation( - ref DtoaBuilder buffer, + ref DtoaBuilder buffer, int exponent, bool negative, int significantDigits) @@ -401,7 +401,7 @@ private JsValue ToNumberString(JsValue thisObject, JsCallArguments arguments) } var integer = (long) x; - var fraction = x - integer; + var fraction = x - integer; string result = NumberPrototype.ToBase(integer, radix); if (fraction != 0) @@ -445,7 +445,7 @@ internal static string ToFractionBase(double n, int radix) var result = new ValueStringBuilder(stackalloc char[64]); while (n > 0 && result.Length < 50) // arbitrary limit { - var c = n*radix; + var c = n * radix; var d = (int) c; n = c - d; diff --git a/Jint/Native/Object/ObjectConstructor.cs b/Jint/Native/Object/ObjectConstructor.cs index 9075af1fff..3391a395b3 100644 --- a/Jint/Native/Object/ObjectConstructor.cs +++ b/Jint/Native/Object/ObjectConstructor.cs @@ -138,7 +138,7 @@ protected internal override JsValue Call(JsValue thisObject, JsCallArguments arg return Construct(arguments); } - if(arguments[0].IsNullOrUndefined()) + if (arguments[0].IsNullOrUndefined()) { return Construct(arguments); } @@ -186,7 +186,7 @@ public override ObjectInstance Construct(JsCallArguments arguments, JsValue newT internal ObjectInstance Construct(int propertyCount) { var obj = new JsObject(_engine); - obj.SetProperties(propertyCount > 0 ? new PropertyDictionary(propertyCount, checkExistingKeys: true) : null); + obj.SetProperties(propertyCount > 0 ? new PropertyDictionary(propertyCount, checkExistingKeys: true) : null); return obj; } diff --git a/Jint/Native/Object/ObjectPrototype.cs b/Jint/Native/Object/ObjectPrototype.cs index d21ef1b13e..341a07053f 100644 --- a/Jint/Native/Object/ObjectPrototype.cs +++ b/Jint/Native/Object/ObjectPrototype.cs @@ -56,7 +56,7 @@ protected override void Initialize() ["toString"] = new LazyPropertyDescriptor(this, static prototype => new ClrFunction(prototype._engine, "toString", prototype.ToObjectString, 0, LengthFlags), PropertyFlags), ["toLocaleString"] = new LazyPropertyDescriptor(this, static prototype => new ClrFunction(prototype._engine, "toLocaleString", prototype.ToLocaleString, 0, LengthFlags), PropertyFlags), ["valueOf"] = new LazyPropertyDescriptor(this, static prototype => new ClrFunction(prototype._engine, "valueOf", prototype.ValueOf, 0, LengthFlags), PropertyFlags), - ["hasOwnProperty"] = new LazyPropertyDescriptor(this, static prototype => new ClrFunction(prototype._engine, "hasOwnProperty",prototype. HasOwnProperty, 1, LengthFlags), PropertyFlags), + ["hasOwnProperty"] = new LazyPropertyDescriptor(this, static prototype => new ClrFunction(prototype._engine, "hasOwnProperty", prototype.HasOwnProperty, 1, LengthFlags), PropertyFlags), ["isPrototypeOf"] = new LazyPropertyDescriptor(this, static prototype => new ClrFunction(prototype._engine, "isPrototypeOf", prototype.IsPrototypeOf, 1, LengthFlags), PropertyFlags), ["propertyIsEnumerable"] = new LazyPropertyDescriptor(this, static prototype => new ClrFunction(prototype._engine, "propertyIsEnumerable", prototype.PropertyIsEnumerable, 1, LengthFlags), PropertyFlags) }; diff --git a/Jint/Native/Promise/PromiseConstructor.cs b/Jint/Native/Promise/PromiseConstructor.cs index f714d2a44d..2dad7c48a8 100644 --- a/Jint/Native/Promise/PromiseConstructor.cs +++ b/Jint/Native/Promise/PromiseConstructor.cs @@ -47,7 +47,7 @@ protected override void Initialize() ["reject"] = new(new PropertyDescriptor(new ClrFunction(Engine, "reject", Reject, 1, LengthFlags), PropertyFlags)), ["resolve"] = new(new PropertyDescriptor(new ClrFunction(Engine, "resolve", Resolve, 1, LengthFlags), PropertyFlags)), ["try"] = new(new PropertyDescriptor(new ClrFunction(Engine, "try", Try, 1, LengthFlags), PropertyFlags)), - ["withResolvers"] = new(new PropertyDescriptor(new ClrFunction(Engine, "withResolvers", WithResolvers , 0, LengthFlags), PropertyFlags)), + ["withResolvers"] = new(new PropertyDescriptor(new ClrFunction(Engine, "withResolvers", WithResolvers, 0, LengthFlags), PropertyFlags)), }; SetProperties(properties); diff --git a/Jint/Native/SharedArrayBuffer/SharedArrayBufferConstructor.cs b/Jint/Native/SharedArrayBuffer/SharedArrayBufferConstructor.cs index 11023f40f5..d0c7ae761e 100644 --- a/Jint/Native/SharedArrayBuffer/SharedArrayBufferConstructor.cs +++ b/Jint/Native/SharedArrayBuffer/SharedArrayBufferConstructor.cs @@ -40,7 +40,7 @@ protected override void Initialize() var symbols = new SymbolDictionary(1) { - [GlobalSymbolRegistry.Species] = new GetSetPropertyDescriptor(get: new ClrFunction(Engine, "get [Symbol.species]", Species, 0, lengthFlags), set: Undefined,PropertyFlag.Configurable), + [GlobalSymbolRegistry.Species] = new GetSetPropertyDescriptor(get: new ClrFunction(Engine, "get [Symbol.species]", Species, 0, lengthFlags), set: Undefined, PropertyFlag.Configurable), }; SetSymbols(symbols); } @@ -84,7 +84,7 @@ public override ObjectInstance Construct(JsCallArguments arguments, JsValue newT return AllocateSharedArrayBuffer(newTarget, byteLength, requestedMaxByteLength); } - private JsSharedArrayBuffer AllocateSharedArrayBuffer(JsValue constructor, uint byteLength, uint? maxByteLength = null) + private JsSharedArrayBuffer AllocateSharedArrayBuffer(JsValue constructor, uint byteLength, uint? maxByteLength = null) { var allocatingGrowableBuffer = maxByteLength != null; diff --git a/Jint/Native/String/StringConstructor.cs b/Jint/Native/String/StringConstructor.cs index f7ee57b10c..f0a5e65b83 100644 --- a/Jint/Native/String/StringConstructor.cs +++ b/Jint/Native/String/StringConstructor.cs @@ -62,11 +62,11 @@ private static JsValue FromCharCode(JsValue? thisObj, JsCallArguments arguments) } #if SUPPORTS_SPAN_PARSE - var elements = length < 512 ? stackalloc char[length] : new char[length]; + var elements = length < 512 ? stackalloc char[length] : new char[length]; #else var elements = new char[length]; #endif - for (var i = 0; i < elements.Length; i++ ) + for (var i = 0; i < elements.Length; i++) { var nextCu = TypeConverter.ToUint16(arguments[i]); elements[i] = (char) nextCu; @@ -122,7 +122,7 @@ private JsValue FromCodePoint(JsValue thisObject, JsCallArguments arguments) return JsString.Create(result.ToString()); - rangeError: +rangeError: _engine.SignalError(ExceptionHelper.CreateRangeError(_realm, "Invalid code point " + codePoint)); return JsEmpty.Instance; } diff --git a/Jint/Native/String/StringPrototype.cs b/Jint/Native/String/StringPrototype.cs index accd048d5c..b9d7dca44b 100644 --- a/Jint/Native/String/StringPrototype.cs +++ b/Jint/Native/String/StringPrototype.cs @@ -598,7 +598,7 @@ private JsValue Replace(JsValue thisObject, JsCallArguments arguments) else { var captures = System.Array.Empty(); - replStr = RegExpPrototype.GetSubstitution(searchString, thisString.ToString(), position, captures, Undefined, TypeConverter.ToString(replaceValue)); + replStr = RegExpPrototype.GetSubstitution(searchString, thisString.ToString(), position, captures, Undefined, TypeConverter.ToString(replaceValue)); } var tailPos = position + searchString.Length; @@ -686,7 +686,7 @@ static int StringIndexOf(string s, string search, int fromIndex) else { var captures = System.Array.Empty(); - replacement = RegExpPrototype.GetSubstitution(searchString, thisString, position, captures, Undefined, TypeConverter.ToString(replaceValue)); + replacement = RegExpPrototype.GetSubstitution(searchString, thisString, position, captures, Undefined, TypeConverter.ToString(replaceValue)); } result.Append(preserved); @@ -789,7 +789,7 @@ private JsValue LastIndexOf(JsValue thisObject, JsCallArguments arguments) var pos = double.IsNaN(numPos) ? double.PositiveInfinity : TypeConverter.ToInteger(numPos); var len = jsString.Length; - var start = (int)System.Math.Min(System.Math.Max(pos, 0), len); + var start = (int) System.Math.Min(System.Math.Max(pos, 0), len); var searchLen = searchStr.Length; if (searchLen > len) @@ -899,7 +899,7 @@ private JsValue CodePointAt(JsValue thisObject, JsCallArguments arguments) JsValue pos = arguments.Length > 0 ? arguments[0] : 0; var s = TypeConverter.ToString(thisObject); - var position = (int)TypeConverter.ToInteger(pos); + var position = (int) TypeConverter.ToInteger(pos); if (position < 0 || position >= s.Length) { return Undefined; diff --git a/Jint/Native/Symbol/SymbolPrototype.cs b/Jint/Native/Symbol/SymbolPrototype.cs index a69bf52966..70d91e4c22 100644 --- a/Jint/Native/Symbol/SymbolPrototype.cs +++ b/Jint/Native/Symbol/SymbolPrototype.cs @@ -39,9 +39,10 @@ protected override void Initialize() }); SetSymbols(new SymbolDictionary(1) - { - [GlobalSymbolRegistry.ToPrimitive] = new PropertyDescriptor(new ClrFunction(Engine, "[Symbol.toPrimitive]", ToPrimitive, 1, lengthFlags), propertyFlags), [GlobalSymbolRegistry.ToStringTag] = new PropertyDescriptor(new JsString("Symbol"), propertyFlags) - } + { + [GlobalSymbolRegistry.ToPrimitive] = new PropertyDescriptor(new ClrFunction(Engine, "[Symbol.toPrimitive]", ToPrimitive, 1, lengthFlags), propertyFlags), + [GlobalSymbolRegistry.ToStringTag] = new PropertyDescriptor(new JsString("Symbol"), propertyFlags) + } ); } diff --git a/Jint/Native/TypedArray/IntrinsicTypedArrayPrototype.cs b/Jint/Native/TypedArray/IntrinsicTypedArrayPrototype.cs index 7127768b11..6bb5bc887b 100644 --- a/Jint/Native/TypedArray/IntrinsicTypedArrayPrototype.cs +++ b/Jint/Native/TypedArray/IntrinsicTypedArrayPrototype.cs @@ -49,7 +49,7 @@ protected override void Initialize() ["fill"] = new LazyPropertyDescriptor(this, static prototype => new ClrFunction(prototype._engine, "fill", prototype.Fill, 1, PropertyFlag.Configurable), PropertyFlags), ["filter"] = new LazyPropertyDescriptor(this, static prototype => new ClrFunction(prototype._engine, "filter", prototype.Filter, 1, PropertyFlag.Configurable), PropertyFlags), ["find"] = new LazyPropertyDescriptor(this, static prototype => new ClrFunction(prototype._engine, "find", prototype.Find, 1, PropertyFlag.Configurable), PropertyFlags), - ["findIndex"] = new LazyPropertyDescriptor(this, static prototype => new ClrFunction(prototype._engine, "findIndex",prototype. FindIndex, 1, PropertyFlag.Configurable), PropertyFlags), + ["findIndex"] = new LazyPropertyDescriptor(this, static prototype => new ClrFunction(prototype._engine, "findIndex", prototype.FindIndex, 1, PropertyFlag.Configurable), PropertyFlags), ["findLast"] = new LazyPropertyDescriptor(this, static prototype => new ClrFunction(prototype._engine, "findLast", prototype.FindLast, 1, PropertyFlag.Configurable), PropertyFlags), ["findLastIndex"] = new LazyPropertyDescriptor(this, static prototype => new ClrFunction(prototype._engine, "findLastIndex", prototype.FindLastIndex, 1, PropertyFlag.Configurable), PropertyFlags), ["forEach"] = new LazyPropertyDescriptor(this, static prototype => new ClrFunction(prototype._engine, "forEach", prototype.ForEach, 1, PropertyFlag.Configurable), PropertyFlags), @@ -205,7 +205,7 @@ public uint TypedArrayLength return o._arrayLength; } - var byteOffset = o._byteOffset; + var byteOffset = o._byteOffset; var elementSize = o._arrayElementType.GetElementSize(); var byteLength = (double) CachedBufferByteLength; var floor = System.Math.Floor((byteLength - byteOffset) / elementSize); diff --git a/Jint/Native/TypedArray/TypedArrayConstructor.cs b/Jint/Native/TypedArray/TypedArrayConstructor.cs index 895be71ea0..3978507bb4 100644 --- a/Jint/Native/TypedArray/TypedArrayConstructor.cs +++ b/Jint/Native/TypedArray/TypedArrayConstructor.cs @@ -297,7 +297,7 @@ internal JsTypedArray AllocateTypedArray(JsValue newTarget, uint length = 0) return obj; } - internal static void FillTypedArrayInstance(JsTypedArray target, ReadOnlySpanvalues) + internal static void FillTypedArrayInstance(JsTypedArray target, ReadOnlySpan values) { for (var i = 0; i < values.Length; ++i) { diff --git a/Jint/Native/TypedArray/Uint8ArrayPrototype.cs b/Jint/Native/TypedArray/Uint8ArrayPrototype.cs index 120faa3dd7..1d1b3761f7 100644 --- a/Jint/Native/TypedArray/Uint8ArrayPrototype.cs +++ b/Jint/Native/TypedArray/Uint8ArrayPrototype.cs @@ -119,7 +119,7 @@ private JsObject SetFromHex(JsValue thisObject, JsCallArguments arguments) private JsValue ToBase64(JsValue thisObject, JsCallArguments arguments) { - var o = ValidateUint8Array(thisObject); + var o = ValidateUint8Array(thisObject); var opts = Uint8ArrayConstructor.GetOptionsObject(_engine, arguments.At(0)); var alphabet = Uint8ArrayConstructor.GetAndValidateAlphabetOption(_engine, opts); @@ -156,11 +156,11 @@ private JsValue ToHex(JsValue thisObject, JsCallArguments arguments) using var outString = new ValueStringBuilder(); foreach (var b in toEncode) { - var b1 = (byte)(b >> 4); - outString.Append((char)(b1 > 9 ? b1 - 10 + 'a' : b1 + '0')); + var b1 = (byte) (b >> 4); + outString.Append((char) (b1 > 9 ? b1 - 10 + 'a' : b1 + '0')); - var b2 = (byte)(b & 0x0F); - outString.Append((char)(b2 > 9 ? b2 - 10 + 'a' : b2 + '0')); + var b2 = (byte) (b & 0x0F); + outString.Append((char) (b2 > 9 ? b2 - 10 + 'a' : b2 + '0')); } return outString.ToString(); diff --git a/Jint/Native/WeakMap/WeakMapConstructor.cs b/Jint/Native/WeakMap/WeakMapConstructor.cs index 4a5789c761..6d05554b99 100644 --- a/Jint/Native/WeakMap/WeakMapConstructor.cs +++ b/Jint/Native/WeakMap/WeakMapConstructor.cs @@ -34,7 +34,7 @@ public override ObjectInstance Construct(JsCallArguments arguments, JsValue newT var map = OrdinaryCreateFromConstructor( newTarget, - static intrinsics => intrinsics.WeakMap.PrototypeObject, + static intrinsics => intrinsics.WeakMap.PrototypeObject, static (Engine engine, Realm _, object? _) => new JsWeakMap(engine)); if (arguments.Length > 0 && !arguments[0].IsNullOrUndefined()) { diff --git a/Jint/Pooling/ValueStringBuilder.cs b/Jint/Pooling/ValueStringBuilder.cs index 07763992df..6ff1a621e0 100644 --- a/Jint/Pooling/ValueStringBuilder.cs +++ b/Jint/Pooling/ValueStringBuilder.cs @@ -48,7 +48,7 @@ public void EnsureCapacity(int capacity) Debug.Assert(capacity >= 0); // If the caller has a bug and calls this with negative capacity, make sure to call Grow to throw an exception. - if ((uint)capacity > (uint)_chars.Length) + if ((uint) capacity > (uint) _chars.Length) Grow(capacity - _pos); } @@ -177,7 +177,7 @@ public void Append(char c) { int pos = _pos; Span chars = _chars; - if ((uint)pos < (uint)chars.Length) + if ((uint) pos < (uint) chars.Length) { chars[pos] = c; _pos = pos + 1; @@ -209,7 +209,7 @@ public void Append(string? s) } int pos = _pos; - if (s.Length == 1 && (uint)pos < (uint)_chars.Length) // very common case, e.g. appending strings from NumberFormatInfo like separators, percent symbols, etc. + if (s.Length == 1 && (uint) pos < (uint) _chars.Length) // very common case, e.g. appending strings from NumberFormatInfo like separators, percent symbols, etc. { _chars[pos] = s[0]; _pos = pos + 1; @@ -344,9 +344,9 @@ private void Grow(int additionalCapacityBeyondPos) // Increase to at least the required size (_pos + additionalCapacityBeyondPos), but try // to double the size if possible, bounding the doubling to not go beyond the max array length. - int newCapacity = (int)Math.Max( - (uint)(_pos + additionalCapacityBeyondPos), - Math.Min((uint)_chars.Length * 2, ArrayMaxLength)); + int newCapacity = (int) Math.Max( + (uint) (_pos + additionalCapacityBeyondPos), + Math.Min((uint) _chars.Length * 2, ArrayMaxLength)); // Make sure to let Rent throw an exception if the caller has a bug and the desired capacity is negative. // This could also go negative if the actual required length wraps around. diff --git a/Jint/Runtime/CallStack/CallStackElementComparer.cs b/Jint/Runtime/CallStack/CallStackElementComparer.cs index 7068d5f146..631de003d7 100644 --- a/Jint/Runtime/CallStack/CallStackElementComparer.cs +++ b/Jint/Runtime/CallStack/CallStackElementComparer.cs @@ -1,6 +1,6 @@ namespace Jint.Runtime.CallStack; -internal sealed class CallStackElementComparer: IEqualityComparer +internal sealed class CallStackElementComparer : IEqualityComparer { public static readonly CallStackElementComparer Instance = new(); diff --git a/Jint/Runtime/DefaultTimeSystem.cs b/Jint/Runtime/DefaultTimeSystem.cs index eee9823e9f..d65af73b11 100644 --- a/Jint/Runtime/DefaultTimeSystem.cs +++ b/Jint/Runtime/DefaultTimeSystem.cs @@ -68,7 +68,7 @@ public virtual bool TryParse(string date, out long epochMilliseconds) } // special check for large years that always require + or - in front and have 6 digit year - if ((date[0] == '+'|| date[0] == '-') && date.IndexOf('-', 1) == 7) + if ((date[0] == '+' || date[0] == '-') && date.IndexOf('-', 1) == 7) { return TryParseLargeYear(date, out epochMilliseconds); } diff --git a/Jint/Runtime/Environments/DeclarativeEnvironment.cs b/Jint/Runtime/Environments/DeclarativeEnvironment.cs index 309e23d9f4..80f5d23417 100644 --- a/Jint/Runtime/Environments/DeclarativeEnvironment.cs +++ b/Jint/Runtime/Environments/DeclarativeEnvironment.cs @@ -196,7 +196,7 @@ internal static void CreateMutableBinding(this T dictionary, Key name, bool c } [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static void CreateImmutableBinding(this T dictionary, Key name, bool strict = true) where T : IEngineDictionary + internal static void CreateImmutableBinding(this T dictionary, Key name, bool strict = true) where T : IEngineDictionary { dictionary[name] = new Binding(null!, canBeDeleted: false, mutable: false, strict); } diff --git a/Jint/Runtime/Environments/FunctionEnvironment.cs b/Jint/Runtime/Environments/FunctionEnvironment.cs index 1d3e9989cf..5459963e46 100644 --- a/Jint/Runtime/Environments/FunctionEnvironment.cs +++ b/Jint/Runtime/Environments/FunctionEnvironment.cs @@ -190,7 +190,7 @@ private void HandleObjectPattern(EvaluationContext context, bool initiallyEmpty, ExceptionHelper.ThrowTypeError(_functionObject._realm, "Destructed parameter is null or undefined"); } - var argumentObject = TypeConverter.ToObject(_engine.Realm , argument); + var argumentObject = TypeConverter.ToObject(_engine.Realm, argument); ref readonly var properties = ref objectPattern.Properties; var processedProperties = properties.Count > 0 && properties[properties.Count - 1] is RestElement diff --git a/Jint/Runtime/ITimeSystem.cs b/Jint/Runtime/ITimeSystem.cs index 07729dec1a..85daccbcf7 100644 --- a/Jint/Runtime/ITimeSystem.cs +++ b/Jint/Runtime/ITimeSystem.cs @@ -15,7 +15,7 @@ public interface ITimeSystem /// /// Current UTC time. DateTimeOffset GetUtcNow(); - + /// /// Return the default time zone system is using. Usually , but can be altered via /// engine configuration, see . diff --git a/Jint/Runtime/Interop/DefaultObjectConverter.cs b/Jint/Runtime/Interop/DefaultObjectConverter.cs index ec6478f01e..e11f8c0144 100644 --- a/Jint/Runtime/Interop/DefaultObjectConverter.cs +++ b/Jint/Runtime/Interop/DefaultObjectConverter.cs @@ -81,20 +81,20 @@ public static bool TryConvert(Engine engine, object value, Type? type, [NotNullW } #if NETSTANDARD2_1_OR_GREATER || NETCOREAPP - if (value is ValueTask valueTask) - { - result = JsValue.ConvertAwaitableToPromise(engine, valueTask); - return result is not null; - } + if (value is ValueTask valueTask) + { + result = JsValue.ConvertAwaitableToPromise(engine, valueTask); + return result is not null; + } #endif } #if NET8_0_OR_GREATER - if (value is System.Text.Json.Nodes.JsonValue jsonValue) - { - result = ConvertSystemTextJsonValue(engine, jsonValue); - return result is not null; - } + if (value is System.Text.Json.Nodes.JsonValue jsonValue) + { + result = ConvertSystemTextJsonValue(engine, jsonValue); + return result is not null; + } #endif var t = value.GetType(); @@ -160,23 +160,23 @@ public static bool TryConvert(Engine engine, object value, Type? type, [NotNullW } #if NET8_0_OR_GREATER - private static JsValue? ConvertSystemTextJsonValue(Engine engine, System.Text.Json.Nodes.JsonValue value) + private static JsValue? ConvertSystemTextJsonValue(Engine engine, System.Text.Json.Nodes.JsonValue value) + { + return value.GetValueKind() switch { - return value.GetValueKind() switch - { - System.Text.Json.JsonValueKind.Object => JsValue.FromObject(engine, value), - System.Text.Json.JsonValueKind.Array => JsValue.FromObject(engine, value), - System.Text.Json.JsonValueKind.String => JsString.Create(value.ToString()), + System.Text.Json.JsonValueKind.Object => JsValue.FromObject(engine, value), + System.Text.Json.JsonValueKind.Array => JsValue.FromObject(engine, value), + System.Text.Json.JsonValueKind.String => JsString.Create(value.ToString()), #pragma warning disable IL2026, IL3050 - System.Text.Json.JsonValueKind.Number => value.TryGetValue(out var intValue) ? JsNumber.Create(intValue) : System.Text.Json.JsonSerializer.Deserialize(value), + System.Text.Json.JsonValueKind.Number => value.TryGetValue(out var intValue) ? JsNumber.Create(intValue) : System.Text.Json.JsonSerializer.Deserialize(value), #pragma warning restore IL2026, IL3050 - System.Text.Json.JsonValueKind.True => JsBoolean.True, - System.Text.Json.JsonValueKind.False => JsBoolean.False, - System.Text.Json.JsonValueKind.Undefined => JsValue.Undefined, - System.Text.Json.JsonValueKind.Null => JsValue.Null, - _ => null - }; - } + System.Text.Json.JsonValueKind.True => JsBoolean.True, + System.Text.Json.JsonValueKind.False => JsBoolean.False, + System.Text.Json.JsonValueKind.Undefined => JsValue.Undefined, + System.Text.Json.JsonValueKind.Null => JsValue.Null, + _ => null + }; + } #endif private static bool TryConvertConvertible(Engine engine, IConvertible convertible, [NotNullWhen(true)] out JsValue? result) diff --git a/Jint/Runtime/Interop/DelegateWrapper.cs b/Jint/Runtime/Interop/DelegateWrapper.cs index c79dc2fe30..ab1969d807 100644 --- a/Jint/Runtime/Interop/DelegateWrapper.cs +++ b/Jint/Runtime/Interop/DelegateWrapper.cs @@ -158,19 +158,19 @@ private static bool IsAwaitable(object? obj) return true; } #if NETSTANDARD2_1_OR_GREATER || NETCOREAPP - if (obj is ValueTask) - { - return true; - } + if (obj is ValueTask) + { + return true; + } - // ValueTask is not derived from ValueTask, so we need to check for it explicitly - var type = obj.GetType(); - if (!type.IsGenericType) - { - return false; - } + // ValueTask is not derived from ValueTask, so we need to check for it explicitly + var type = obj.GetType(); + if (!type.IsGenericType) + { + return false; + } - return type.GetGenericTypeDefinition() == typeof(ValueTask<>); + return type.GetGenericTypeDefinition() == typeof(ValueTask<>); #else return false; #endif diff --git a/Jint/Runtime/Interop/GetterFunction.cs b/Jint/Runtime/Interop/GetterFunction.cs index 5332ebcbb3..37923aa81e 100644 --- a/Jint/Runtime/Interop/GetterFunction.cs +++ b/Jint/Runtime/Interop/GetterFunction.cs @@ -6,7 +6,7 @@ namespace Jint.Runtime.Interop; /// /// Represents a FunctionInstance wrapping a CLR getter. /// -internal sealed class GetterFunction: Function +internal sealed class GetterFunction : Function { private static readonly JsString _name = new JsString("get"); private readonly Func _getter; diff --git a/Jint/Runtime/Interop/ObjectWrapper.cs b/Jint/Runtime/Interop/ObjectWrapper.cs index f45f56e938..65c39cdc29 100644 --- a/Jint/Runtime/Interop/ObjectWrapper.cs +++ b/Jint/Runtime/Interop/ObjectWrapper.cs @@ -215,7 +215,7 @@ public override JsValue Get(JsValue property, JsValue receiver) public override List GetOwnPropertyKeys(Types types = Types.Empty | Types.String | Types.Symbol) { - return [..EnumerateOwnPropertyKeys(types)]; + return [.. EnumerateOwnPropertyKeys(types)]; } public override IEnumerable> GetOwnProperties() @@ -225,7 +225,7 @@ public override IEnumerable> GetOwnPro yield return new KeyValuePair(key, GetOwnProperty(key)); } } - + private IEnumerable EnumerateOwnPropertyKeys(Types types) { // prefer object order, add possible other properties after diff --git a/Jint/Runtime/Interop/Reflection/IndexerAccessor.cs b/Jint/Runtime/Interop/Reflection/IndexerAccessor.cs index c05b409598..291e028f5c 100644 --- a/Jint/Runtime/Interop/Reflection/IndexerAccessor.cs +++ b/Jint/Runtime/Interop/Reflection/IndexerAccessor.cs @@ -88,7 +88,7 @@ internal static bool TryFindIndexer( indexerAccessor = ComposeIndexerFactory(engine, targetType, candidate, paramType, propertyName, integerKey, paramTypeArray); if (indexerAccessor != null) { - if (paramType != typeof(string) || integerKey is null) + if (paramType != typeof(string) || integerKey is null) { // exact match, we don't need to check for integer key indexer = candidate; diff --git a/Jint/Runtime/Interop/TypeReference.cs b/Jint/Runtime/Interop/TypeReference.cs index c5ca07f3be..e665b4b944 100644 --- a/Jint/Runtime/Interop/TypeReference.cs +++ b/Jint/Runtime/Interop/TypeReference.cs @@ -308,7 +308,7 @@ private static ReflectionAccessor ResolveMemberAccessor( var memberNameComparer = typeResolver.MemberNameComparer; var typeResolverMemberNameCreator = typeResolver.MemberNameCreator; #if NET7_0_OR_GREATER - var enumValues = type.GetEnumValuesAsUnderlyingType(); + var enumValues = type.GetEnumValuesAsUnderlyingType(); #else var enumValues = Enum.GetValues(type); #endif diff --git a/Jint/Runtime/Interop/TypeResolver.cs b/Jint/Runtime/Interop/TypeResolver.cs index eb863735a3..5dddd223f0 100644 --- a/Jint/Runtime/Interop/TypeResolver.cs +++ b/Jint/Runtime/Interop/TypeResolver.cs @@ -274,7 +274,7 @@ private static int CalculateIndexerScore(ParameterInfo parameter, bool isInteger if (paramType == typeof(int)) { - return isInteger ? 0 : 10; + return isInteger ? 0 : 10; } if (paramType == typeof(string)) @@ -483,7 +483,7 @@ public override bool Equals(string? x, string? y) if (equals && x.Length > 1) { #if SUPPORTS_SPAN_PARSE - equals = x.AsSpan(1).SequenceEqual(y.AsSpan(1)); + equals = x.AsSpan(1).SequenceEqual(y.AsSpan(1)); #else equals = string.Equals(x.Substring(1), y.Substring(1), StringComparison.Ordinal); #endif diff --git a/Jint/Runtime/Interpreter/DeclarationCache.cs b/Jint/Runtime/Interpreter/DeclarationCache.cs index 5958619b98..81006cae2f 100644 --- a/Jint/Runtime/Interpreter/DeclarationCache.cs +++ b/Jint/Runtime/Interpreter/DeclarationCache.cs @@ -67,7 +67,7 @@ public static DeclarationCache Build(SwitchCase statement) continue; } - var rootVariable = (VariableDeclaration)node; + var rootVariable = (VariableDeclaration) node; if (rootVariable.Kind == VariableDeclarationKind.Var) { continue; diff --git a/Jint/Runtime/Interpreter/Expressions/DestructuringPatternAssignmentExpression.cs b/Jint/Runtime/Interpreter/Expressions/DestructuringPatternAssignmentExpression.cs index c149aa7957..2102ac44d4 100644 --- a/Jint/Runtime/Interpreter/Expressions/DestructuringPatternAssignmentExpression.cs +++ b/Jint/Runtime/Interpreter/Expressions/DestructuringPatternAssignmentExpression.cs @@ -222,7 +222,7 @@ private static JsValue HandleArrayPattern( } else { - AssignToReference(engine, reference!, array, environment); + AssignToReference(engine, reference!, array, environment); } } else if (left is AssignmentPattern assignmentPattern) diff --git a/Jint/Runtime/Interpreter/Expressions/JintBinaryExpression.cs b/Jint/Runtime/Interpreter/Expressions/JintBinaryExpression.cs index ea8a50bf1f..11b04c1b9b 100644 --- a/Jint/Runtime/Interpreter/Expressions/JintBinaryExpression.cs +++ b/Jint/Runtime/Interpreter/Expressions/JintBinaryExpression.cs @@ -298,7 +298,7 @@ protected override object EvaluateInternal(EvaluationContext context) if (AreIntegerOperands(left, right)) { - return JsNumber.Create((long)left.AsInteger() + right.AsInteger()); + return JsNumber.Create((long) left.AsInteger() + right.AsInteger()); } var lprim = TypeConverter.ToPrimitive(left); @@ -308,7 +308,7 @@ protected override object EvaluateInternal(EvaluationContext context) { result = JsString.Create(TypeConverter.ToString(lprim) + TypeConverter.ToString(rprim)); } - else if (AreNonBigIntOperands(left,right)) + else if (AreNonBigIntOperands(left, right)) { result = JsNumber.Create(TypeConverter.ToNumber(lprim) + TypeConverter.ToNumber(rprim)); } @@ -347,7 +347,7 @@ protected override object EvaluateInternal(EvaluationContext context) if (AreIntegerOperands(left, right)) { - number = JsNumber.Create((long)left.AsInteger() - right.AsInteger()); + number = JsNumber.Create((long) left.AsInteger() - right.AsInteger()); } else if (AreNonBigIntOperands(left, right)) { @@ -525,7 +525,7 @@ protected override object EvaluateInternal(EvaluationContext context) var right = TypeConverter.ToNumeric(rightReference); JsValue result; - if (AreNonBigIntOperands(left,right)) + if (AreNonBigIntOperands(left, right)) { // validation var baseNumber = (JsNumber) left; diff --git a/Jint/Runtime/Interpreter/Expressions/JintSequenceExpression.cs b/Jint/Runtime/Interpreter/Expressions/JintSequenceExpression.cs index efb4f1132d..15078e1b6a 100644 --- a/Jint/Runtime/Interpreter/Expressions/JintSequenceExpression.cs +++ b/Jint/Runtime/Interpreter/Expressions/JintSequenceExpression.cs @@ -31,7 +31,7 @@ protected override object EvaluateInternal(EvaluationContext context) Initialize(); _initialized = true; } - + var result = JsValue.Undefined; foreach (var expression in _expressions) { diff --git a/Jint/Runtime/Interpreter/JintFunctionDefinition.cs b/Jint/Runtime/Interpreter/JintFunctionDefinition.cs index 9394f5615f..f4adcea9b1 100644 --- a/Jint/Runtime/Interpreter/JintFunctionDefinition.cs +++ b/Jint/Runtime/Interpreter/JintFunctionDefinition.cs @@ -330,7 +330,7 @@ private static void GetBoundNames( ref bool hasDuplicates, ref bool hasArguments) { - Start: +Start: if (parameter.Type == NodeType.Identifier) { var key = (Key) ((Identifier) parameter).Name; diff --git a/Jint/Runtime/Interpreter/Statements/ConstantReturnStatement.cs b/Jint/Runtime/Interpreter/Statements/ConstantReturnStatement.cs index e441324194..b1de86555b 100644 --- a/Jint/Runtime/Interpreter/Statements/ConstantReturnStatement.cs +++ b/Jint/Runtime/Interpreter/Statements/ConstantReturnStatement.cs @@ -5,7 +5,7 @@ namespace Jint.Runtime.Interpreter.Statements; internal sealed class ConstantStatement : JintStatement { private readonly JsValue _value; - private CompletionType _completionType; + private readonly CompletionType _completionType; public ConstantStatement(Statement statement, CompletionType completionType, JsValue value) : base(statement) { diff --git a/Jint/Runtime/Interpreter/Statements/JintSwitchBlock.cs b/Jint/Runtime/Interpreter/Statements/JintSwitchBlock.cs index 78233ad789..28df41c9d5 100644 --- a/Jint/Runtime/Interpreter/Statements/JintSwitchBlock.cs +++ b/Jint/Runtime/Interpreter/Statements/JintSwitchBlock.cs @@ -44,7 +44,7 @@ public Completion Execute(EvaluationContext context, JsValue input) DeclarativeEnvironment? blockEnv = null; - start: +start: for (; i < temp.Length; i++) { var clause = temp[i]; diff --git a/Jint/Runtime/OrderedSet.cs b/Jint/Runtime/OrderedSet.cs index 753cbcd0e6..4bc8d5962c 100644 --- a/Jint/Runtime/OrderedSet.cs +++ b/Jint/Runtime/OrderedSet.cs @@ -36,7 +36,7 @@ public OrderedSet Clone() return new OrderedSet(EqualityComparer.Default) { _set = new HashSet(this._set, this._set.Comparer), - _list = [..this._list] + _list = [.. this._list] }; } diff --git a/Jint/Runtime/TypeConverter.cs b/Jint/Runtime/TypeConverter.cs index 49e4eaca31..856a9abc89 100644 --- a/Jint/Runtime/TypeConverter.cs +++ b/Jint/Runtime/TypeConverter.cs @@ -287,7 +287,7 @@ private static double ToNumber(string input) return -0.0; } - return firstChar == '-' ? - 1 * n : n; + return firstChar == '-' ? -1 * n : n; } catch (Exception e) when (e is OverflowException) { @@ -670,7 +670,7 @@ internal static bool TryStringToBigInt(string str, out BigInteger result) { // we get better precision if we don't hit floating point parsing that is performed by Esprima #if SUPPORTS_SPAN_PARSE - var source = str.AsSpan(2); + var source = str.AsSpan(2); #else var source = str.Substring(2); #endif