diff --git a/Jint.Benchmark/DromaeoBenchmark.cs b/Jint.Benchmark/DromaeoBenchmark.cs index 8e81a7a845..ad77dd7cab 100644 --- a/Jint.Benchmark/DromaeoBenchmark.cs +++ b/Jint.Benchmark/DromaeoBenchmark.cs @@ -16,7 +16,7 @@ public class DromaeoBenchmark {"dromaeo-string-base64", null} }; - private Dictionary _prepared = new(); + private readonly Dictionary _prepared = new(); private Engine engine; diff --git a/Jint.Benchmark/EngineConstructionBenchmark.cs b/Jint.Benchmark/EngineConstructionBenchmark.cs index c6751cd12b..56522b1307 100644 --- a/Jint.Benchmark/EngineConstructionBenchmark.cs +++ b/Jint.Benchmark/EngineConstructionBenchmark.cs @@ -21,4 +21,4 @@ public double BuildEngine() var engine = new Engine(); return engine.Evaluate(_program).AsNumber(); } -} \ No newline at end of file +} diff --git a/Jint.Tests/Runtime/ExtensionMethods/ObservableExtensions.cs b/Jint.Tests/Runtime/ExtensionMethods/ObservableExtensions.cs index b45a0f794a..d770ee9edb 100644 --- a/Jint.Tests/Runtime/ExtensionMethods/ObservableExtensions.cs +++ b/Jint.Tests/Runtime/ExtensionMethods/ObservableExtensions.cs @@ -6,7 +6,7 @@ internal class Subscribe : IObserver private readonly Action onError; private readonly Action onCompleted; - int isStopped = 0; + readonly int isStopped = 0; public Subscribe(Action onNext, Action onError, Action onCompleted) { @@ -65,7 +65,7 @@ public static IObservable Where(this IObservable source, Func : IObservable { - private List> observers = new List>(); + private readonly List> observers = new List>(); public T Last { get; private set; } @@ -78,8 +78,8 @@ public IDisposable Subscribe(IObserver observer) private class Unsubscriber : IDisposable { - private List> _observers; - private IObserver _observer; + private readonly List> _observers; + private readonly IObserver _observer; public Unsubscriber(List> observers, IObserver observer) { diff --git a/Jint.Tests/Runtime/GenericMethodTests.cs b/Jint.Tests/Runtime/GenericMethodTests.cs index ca2cadc071..2ce30cb441 100644 --- a/Jint.Tests/Runtime/GenericMethodTests.cs +++ b/Jint.Tests/Runtime/GenericMethodTests.cs @@ -140,7 +140,7 @@ public void Foo(U u) public class TestGenericBaseClass { - private System.Collections.Generic.List _list = new System.Collections.Generic.List(); + private readonly System.Collections.Generic.List _list = new System.Collections.Generic.List(); public int Count { diff --git a/Jint.Tests/Runtime/InteropTests.MemberAccess.cs b/Jint.Tests/Runtime/InteropTests.MemberAccess.cs index 076b254d99..404ca08f1e 100644 --- a/Jint.Tests/Runtime/InteropTests.MemberAccess.cs +++ b/Jint.Tests/Runtime/InteropTests.MemberAccess.cs @@ -200,7 +200,7 @@ private static class EchoService private class CustomDictionary : IDictionary { - Dictionary _dictionary = new Dictionary(); + readonly Dictionary _dictionary = new Dictionary(); public TValue this[string key] { diff --git a/Jint.Tests/Runtime/JsValueConversionTests.cs b/Jint.Tests/Runtime/JsValueConversionTests.cs index 5e61c1df8e..386684c0b2 100644 --- a/Jint.Tests/Runtime/JsValueConversionTests.cs +++ b/Jint.Tests/Runtime/JsValueConversionTests.cs @@ -5,7 +5,7 @@ namespace Jint.Tests.Runtime { public class JsValueConversionTests { - private Engine _engine; + private readonly Engine _engine; public JsValueConversionTests() { diff --git a/Jint/Agent.cs b/Jint/Agent.cs index 85d4640303..44c8f5c55c 100644 --- a/Jint/Agent.cs +++ b/Jint/Agent.cs @@ -7,7 +7,7 @@ namespace Jint; /// internal sealed class Agent { - private List _keptAlive = new(); + private readonly List _keptAlive = new(); public void AddToKeptObjects(JsValue target) { diff --git a/Jint/Native/Number/Dtoa/Bignum.cs b/Jint/Native/Number/Dtoa/Bignum.cs index cddbd525e4..ac874ccbe3 100644 --- a/Jint/Native/Number/Dtoa/Bignum.cs +++ b/Jint/Native/Number/Dtoa/Bignum.cs @@ -24,7 +24,7 @@ internal sealed class Bignum // grow. There are no checks if the stack-allocated space is sufficient. private const int kBigitCapacity = kMaxSignificantBits / kBigitSize; - private uint[] bigits_ = new uint[kBigitCapacity]; + private readonly uint[] bigits_ = new uint[kBigitCapacity]; // The Bignum's value equals value(bigits_) * 2^(exponent_ * kBigitSize). private int exponent_; @@ -429,7 +429,8 @@ internal void MultiplyByUInt32(uint factor) internal void MultiplyByUInt64(ulong factor) { if (factor == 1) return; - if (factor == 0) { + if (factor == 0) + { Zero(); return; } @@ -437,7 +438,8 @@ internal void MultiplyByUInt64(ulong factor) ulong carry = 0; ulong low = factor & 0xFFFFFFFF; ulong high = factor >> 32; - for (int i = 0; i < used_digits_; ++i) { + for (int i = 0; i < used_digits_; ++i) + { ulong product_low = low * bigits_[i]; ulong product_high = high * bigits_[i]; ulong tmp = (carry & kBigitMask) + product_low; @@ -445,7 +447,8 @@ internal void MultiplyByUInt64(ulong factor) carry = (carry >> kBigitSize) + (tmp >> kBigitSize) + (product_high << (32 - kBigitSize)); } - while (carry != 0) { + while (carry != 0) + { EnsureCapacity(used_digits_ + 1); bigits_[used_digits_] = (uint) (carry & kBigitMask); used_digits_++; @@ -655,4 +658,4 @@ void Square() Clamp(); } } -} \ No newline at end of file +} diff --git a/Jint/Runtime/Interpreter/JintStatementList.cs b/Jint/Runtime/Interpreter/JintStatementList.cs index a909ef9395..74f84a3e90 100644 --- a/Jint/Runtime/Interpreter/JintStatementList.cs +++ b/Jint/Runtime/Interpreter/JintStatementList.cs @@ -19,7 +19,7 @@ private sealed class Pair private Pair[]? _jintStatements; private bool _initialized; - private uint _index; + private readonly uint _index; private readonly bool _generator; public JintStatementList(IFunction function) diff --git a/Jint/Runtime/Modules/CyclicModuleRecord.cs b/Jint/Runtime/Modules/CyclicModuleRecord.cs index 05bea96634..eedaf497be 100644 --- a/Jint/Runtime/Modules/CyclicModuleRecord.cs +++ b/Jint/Runtime/Modules/CyclicModuleRecord.cs @@ -29,7 +29,7 @@ public abstract class CyclicModuleRecord : ModuleRecord protected bool _hasTLA; private bool _asyncEvaluation; private PromiseCapability _topLevelCapability; - private List _asyncParentModules; + private readonly List _asyncParentModules; private int _asyncEvalOrder; private int _pendingAsyncDependencies;