Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Jint/Collections/DictionarySlim.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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))
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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];
Expand Down
8 changes: 4 additions & 4 deletions Jint/Collections/StringDictionarySlim.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -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)
{
Expand Down Expand Up @@ -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];
Expand Down
2 changes: 1 addition & 1 deletion Jint/Engine.Modules.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
4 changes: 2 additions & 2 deletions Jint/Engine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion Jint/Extensions/Character.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
10 changes: 5 additions & 5 deletions Jint/Extensions/Hash.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
/// </summary>
private const int FnvOffsetBias = unchecked((int)2166136261);
private const int FnvOffsetBias = unchecked((int) 2166136261);

/// <summary>
/// The generative factor used in the FNV-1a algorithm
Expand Down Expand Up @@ -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.
Expand Down
66 changes: 33 additions & 33 deletions Jint/Extensions/WebEncoders.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions Jint/HoistingScope.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ??= [];
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion Jint/Jint.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<EnableNETAnalyzers>true</EnableNETAnalyzers>
<AnalysisLevel>latest-Recommended</AnalysisLevel>
<EnforceCodeStyleInBuild>false</EnforceCodeStyleInBuild>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>

<GenerateDocumentationFile>true</GenerateDocumentationFile>
<PackageReadmeFile>README.md</PackageReadmeFile>
Expand Down
6 changes: 3 additions & 3 deletions Jint/Native/Array/ArrayConstructor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
}
Expand All @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion Jint/Native/Array/ArrayIteratorPrototype.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions Jint/Native/Array/ArrayOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
14 changes: 8 additions & 6 deletions Jint/Native/Array/ArrayPrototype.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ protected override void Initialize()
["reduce"] = new LazyPropertyDescriptor<ArrayPrototype>(this, static prototype => new ClrFunction(prototype._engine, "reduce", prototype.Reduce, 1, PropertyFlag.Configurable), PropertyFlags),
["reduceRight"] = new LazyPropertyDescriptor<ArrayPrototype>(this, static prototype => new ClrFunction(prototype._engine, "reduceRight", prototype.ReduceRight, 1, PropertyFlag.Configurable), PropertyFlags),
["reverse"] = new LazyPropertyDescriptor<ArrayPrototype>(this, static prototype => new ClrFunction(prototype._engine, "reverse", prototype.Reverse, 0, PropertyFlag.Configurable), PropertyFlags),
["shift"] = new LazyPropertyDescriptor<ArrayPrototype>(this, static prototype => new ClrFunction(prototype._engine, "shift",prototype. Shift, 0, PropertyFlag.Configurable), PropertyFlags),
["shift"] = new LazyPropertyDescriptor<ArrayPrototype>(this, static prototype => new ClrFunction(prototype._engine, "shift", prototype.Shift, 0, PropertyFlag.Configurable), PropertyFlags),
["slice"] = new LazyPropertyDescriptor<ArrayPrototype>(this, static prototype => new ClrFunction(prototype._engine, "slice", prototype.Slice, 2, PropertyFlag.Configurable), PropertyFlags),
["some"] = new LazyPropertyDescriptor<ArrayPrototype>(this, static prototype => new ClrFunction(prototype._engine, "some", prototype.Some, 1, PropertyFlag.Configurable), PropertyFlags),
["sort"] = new LazyPropertyDescriptor<ArrayPrototype>(this, static prototype => new ClrFunction(prototype._engine, "sort", prototype.Sort, 1, PropertyFlag.Configurable), PropertyFlags),
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion Jint/Native/ArrayBuffer/ArrayBufferConstructor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion Jint/Native/Date/DateConstructor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Loading