Skip to content

Commit

Permalink
Code changes to keep NET 8 analyzers happy (#1685)
Browse files Browse the repository at this point in the history
  • Loading branch information
lahma authored Nov 18, 2023
1 parent 6c36bf2 commit 6653ec8
Show file tree
Hide file tree
Showing 47 changed files with 102 additions and 37 deletions.
4 changes: 2 additions & 2 deletions Jint/Engine.Modules.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ internal ModuleRecord LoadModule(string? referencingModuleLocation, string speci
return module;
}

private CyclicModuleRecord LoadFromBuilder(string specifier, ModuleBuilder moduleBuilder, ResolvedSpecifier moduleResolution)
private BuilderModuleRecord LoadFromBuilder(string specifier, ModuleBuilder moduleBuilder, ResolvedSpecifier moduleResolution)
{
var parsedModule = moduleBuilder.Parse();
var module = new BuilderModuleRecord(this, Realm, parsedModule, null, false);
Expand All @@ -59,7 +59,7 @@ private CyclicModuleRecord LoadFromBuilder(string specifier, ModuleBuilder modul
return module;
}

private CyclicModuleRecord LoaderFromModuleLoader(ResolvedSpecifier moduleResolution)
private SourceTextModuleRecord LoaderFromModuleLoader(ResolvedSpecifier moduleResolution)
{
var parsedModule = ModuleLoader.LoadModule(this, moduleResolution);
var module = new SourceTextModuleRecord(this, Realm, parsedModule, moduleResolution.Uri?.LocalPath, false);
Expand Down
12 changes: 12 additions & 0 deletions Jint/Extensions/Polyfills.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace Jint;

internal static class Polyfills
{
#if NETFRAMEWORK || NETSTANDARD2_0
internal static bool Contains(this string source, char c) => source.IndexOf(c) != -1;
#endif

#if NETFRAMEWORK || NETSTANDARD2_0
internal static bool StartsWith(this string source, char c) => source.Length > 0 && source[0] == c;
#endif
}
2 changes: 2 additions & 0 deletions Jint/Native/Array/ArrayConstructor.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#pragma warning disable CA1859 // Use concrete types when possible for improved performance -- most of constructor methods return JsValue

using System.Collections;
using Jint.Collections;
using Jint.Native.Function;
Expand Down
2 changes: 2 additions & 0 deletions Jint/Native/Array/ArrayPrototype.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#pragma warning disable CA1859 // Use concrete types when possible for improved performance -- most of prototype methods return JsValue

using System.Linq;
using Jint.Collections;
using Jint.Native.Iterator;
Expand Down
2 changes: 2 additions & 0 deletions Jint/Native/ArrayBuffer/ArrayBufferPrototype.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#pragma warning disable CA1859 // Use concrete types when possible for improved performance -- most of prototype methods return JsValue

using Jint.Collections;
using Jint.Native.Object;
using Jint.Native.Symbol;
Expand Down
2 changes: 1 addition & 1 deletion Jint/Native/Boolean/BooleanPrototype.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private JsValue ValueOf(JsValue thisObject, JsValue[] arguments)
return Undefined;
}

private JsValue ToBooleanString(JsValue thisObject, JsValue[] arguments)
private JsString ToBooleanString(JsValue thisObject, JsValue[] arguments)
{
var b = ValueOf(thisObject, Arguments.Empty);
return ((JsBoolean) b)._value ? JsString.TrueString : JsString.FalseString;
Expand Down
2 changes: 2 additions & 0 deletions Jint/Native/DataView/DataViewPrototype.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#pragma warning disable CA1859 // Use concrete types when possible for improved performance -- most of prototype methods return JsValue

using Jint.Collections;
using Jint.Native.ArrayBuffer;
using Jint.Native.Object;
Expand Down
2 changes: 2 additions & 0 deletions Jint/Native/Date/DateConstructor.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#pragma warning disable CA1859 // Use concrete types when possible for improved performance -- most of constructor methods return JsValue

using Jint.Collections;
using Jint.Native.Function;
using Jint.Native.Object;
Expand Down
2 changes: 2 additions & 0 deletions Jint/Native/Date/DatePrototype.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#pragma warning disable CA1859 // Use concrete types when possible for improved performance -- most of prototype methods return JsValue

using System.Globalization;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
Expand Down
1 change: 1 addition & 0 deletions Jint/Native/Date/MimeKit.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#nullable disable
#pragma warning disable CA1510

namespace Jint.Native.Date;

Expand Down
6 changes: 3 additions & 3 deletions Jint/Native/Function/FunctionConstructor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ internal FunctionInstance InstantiateFunctionObject(
/// <summary>
/// https://tc39.es/ecma262/#sec-runtime-semantics-instantiateasyncfunctionobject
/// </summary>
private FunctionInstance InstantiateAsyncFunctionObject(
private ScriptFunctionInstance InstantiateAsyncFunctionObject(
JintFunctionDefinition functionDeclaration,
EnvironmentRecord env,
PrivateEnvironmentRecord? privateEnv)
Expand All @@ -87,7 +87,7 @@ private FunctionInstance InstantiateAsyncFunctionObject(
/// <summary>
/// https://tc39.es/ecma262/#sec-runtime-semantics-instantiateordinaryfunctionobject
/// </summary>
private FunctionInstance InstantiateOrdinaryFunctionObject(
private ScriptFunctionInstance InstantiateOrdinaryFunctionObject(
JintFunctionDefinition functionDeclaration,
EnvironmentRecord env,
PrivateEnvironmentRecord? privateEnv)
Expand All @@ -108,7 +108,7 @@ private FunctionInstance InstantiateOrdinaryFunctionObject(
/// <summary>
/// https://tc39.es/ecma262/#sec-runtime-semantics-instantiategeneratorfunctionobject
/// </summary>
private FunctionInstance InstantiateGeneratorFunctionObject(
private ScriptFunctionInstance InstantiateGeneratorFunctionObject(
JintFunctionDefinition functionDeclaration,
EnvironmentRecord scope,
PrivateEnvironmentRecord? privateScope)
Expand Down
4 changes: 2 additions & 2 deletions Jint/Native/Function/FunctionInstance.Dynamic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ internal FunctionInstance CreateDynamicFunction(
break;
}

if (p.IndexOf('/') != -1)
if (p.Contains('/'))
{
// ensure comments don't screw up things
functionExpression += "\n" + p + "\n";
Expand All @@ -127,7 +127,7 @@ internal FunctionInstance CreateDynamicFunction(

functionExpression += ")";

if (body.IndexOf('/') != -1)
if (body.Contains('/'))
{
// ensure comments don't screw up things
functionExpression += "{\n" + body + "\n}";
Expand Down
2 changes: 2 additions & 0 deletions Jint/Native/Function/FunctionPrototype.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#pragma warning disable CA1859 // Use concrete types when possible for improved performance -- most of prototype methods return JsValue

using Jint.Collections;
using Jint.Native.Array;
using Jint.Native.Object;
Expand Down
6 changes: 3 additions & 3 deletions Jint/Native/Global/GlobalObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ private JsValue Encode(string uriString, string unescapedUriSet)
for (var k = 0; k < strLen; k++)
{
var c = uriString[k];
if (c is >= 'a' and <= 'z' || c is >= 'A' and <= 'Z' || c is >= '0' and <= '9' || unescapedUriSet.IndexOf(c) != -1)
if (c is >= 'a' and <= 'z' || c is >= 'A' and <= 'Z' || c is >= '0' and <= '9' || unescapedUriSet.Contains(c))
{
_stringBuilder.Append(c);
}
Expand Down Expand Up @@ -594,7 +594,7 @@ private static bool IsDigit(char c, int radix, out int result)
/// </summary>
public JsValue Escape(JsValue thisObject, JsValue[] arguments)
{
const string WhiteList = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789@*_ + -./";
const string AllowList = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789@*_ + -./";
var uriString = TypeConverter.ToString(arguments.At(0));

var strLen = uriString.Length;
Expand All @@ -605,7 +605,7 @@ public JsValue Escape(JsValue thisObject, JsValue[] arguments)
for (var k = 0; k < strLen; k++)
{
var c = uriString[k];
if (WhiteList.IndexOf(c) != -1)
if (AllowList.Contains(c))
{
_stringBuilder.Append(c);
}
Expand Down
2 changes: 2 additions & 0 deletions Jint/Native/Intl/IntlInstance.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#pragma warning disable CA1859 // Use concrete types when possible for improved performance -- most of prototype methods return JsValue

using Jint.Collections;
using Jint.Native.Object;
using Jint.Native.Symbol;
Expand Down
2 changes: 1 addition & 1 deletion Jint/Native/Iterator/IteratorInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public virtual void Close(CompletionType completion)
/// <summary>
/// https://tc39.es/ecma262/#sec-createiterresultobject
/// </summary>
private ObjectInstance CreateIterResultObject(JsValue value, bool done)
private IteratorResult CreateIterResultObject(JsValue value, bool done)
{
return new IteratorResult(_engine, value, JsBoolean.Create(done));
}
Expand Down
4 changes: 2 additions & 2 deletions Jint/Native/Json/JsonParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ public bool Match(char value)
return _lookahead.Type == Tokens.Punctuator && value == _lookahead.FirstCharacter;
}

private ObjectInstance ParseJsonArray(ref State state)
private JsArray ParseJsonArray(ref State state)
{
if ((++state.CurrentDepth) > _maxDepth)
{
Expand Down Expand Up @@ -603,7 +603,7 @@ when its full.
return result ?? new JsArray(_engine, elements!.ToArray());
}

private ObjectInstance ParseJsonObject(ref State state)
private JsObject ParseJsonObject(ref State state)
{
if ((++state.CurrentDepth) > _maxDepth)
{
Expand Down
2 changes: 2 additions & 0 deletions Jint/Native/Map/MapConstructor.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#pragma warning disable CA1859 // Use concrete types when possible for improved performance -- most of constructor methods return JsValue

using Jint.Collections;
using Jint.Native.Function;
using Jint.Native.Iterator;
Expand Down
2 changes: 2 additions & 0 deletions Jint/Native/Map/MapPrototype.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#pragma warning disable CA1859 // Use concrete types when possible for improved performance -- most of prototype methods return JsValue

using Jint.Collections;
using Jint.Native.Object;
using Jint.Native.Symbol;
Expand Down
2 changes: 2 additions & 0 deletions Jint/Native/Object/ObjectConstructor.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#pragma warning disable CA1859 // Use concrete types when possible for improved performance -- most of constructor methods return JsValue

using Jint.Collections;
using Jint.Native.Iterator;
using Jint.Runtime;
Expand Down
2 changes: 2 additions & 0 deletions Jint/Native/Object/ObjectPrototype.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#pragma warning disable CA1859 // Use concrete types when possible for improved performance -- most of prototype methods return JsValue

using Jint.Collections;
using Jint.Native.Array;
using Jint.Native.Proxy;
Expand Down
2 changes: 1 addition & 1 deletion Jint/Native/Promise/PromiseConstructor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ internal JsValue Resolve(JsValue thisObject, JsValue[] arguments)
return PromiseResolve(thisObject, x);
}

private JsValue WithResolvers(JsValue thisObject, JsValue[] arguments)
private JsObject WithResolvers(JsValue thisObject, JsValue[] arguments)
{
var promiseCapability = NewPromiseCapability(_engine, thisObject);
var obj = OrdinaryObjectCreate(_engine, _engine.Realm.Intrinsics.Object.PrototypeObject);
Expand Down
4 changes: 2 additions & 2 deletions Jint/Native/Promise/PromisePrototype.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ private JsValue Finally(JsValue thisValue, JsValue[] arguments)
}

// https://tc39.es/ecma262/#sec-thenfinallyfunctions
private JsValue ThenFinallyFunctions(ICallable onFinally, IConstructor ctor) =>
private ClrFunctionInstance ThenFinallyFunctions(ICallable onFinally, IConstructor ctor) =>
new ClrFunctionInstance(_engine, "", (_, args) =>
{
var value = args.At(0);
Expand All @@ -137,7 +137,7 @@ private JsValue ThenFinallyFunctions(ICallable onFinally, IConstructor ctor) =>
}, 1, PropertyFlag.Configurable);

// https://tc39.es/ecma262/#sec-catchfinallyfunctions
private JsValue CatchFinallyFunctions(ICallable onFinally, IConstructor ctor) =>
private ClrFunctionInstance CatchFinallyFunctions(ICallable onFinally, IConstructor ctor) =>
new ClrFunctionInstance(_engine, "", (_, args) =>
{
var reason = args.At(0);
Expand Down
2 changes: 2 additions & 0 deletions Jint/Native/Proxy/ProxyConstructor.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#pragma warning disable CA1859 // Use concrete types when possible for improved performance -- most of constructor methods return JsValue

using Jint.Collections;
using Jint.Native.Object;
using Jint.Runtime;
Expand Down
2 changes: 2 additions & 0 deletions Jint/Native/Reflect/ReflectInstance.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#pragma warning disable CA1859 // Use concrete types when possible for improved performance -- most of prototype methods return JsValue

using Jint.Collections;
using Jint.Native.Function;
using Jint.Native.Object;
Expand Down
2 changes: 1 addition & 1 deletion Jint/Native/RegExp/RegExpConstructor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public override ObjectInstance Construct(JsValue[] arguments, JsValue newTarget)
return RegExpInitialize(r, p, f);
}

private ObjectInstance RegExpInitialize(JsRegExp r, JsValue pattern, JsValue flags)
private JsRegExp RegExpInitialize(JsRegExp r, JsValue pattern, JsValue flags)
{
var p = pattern.IsUndefined() ? "" : TypeConverter.ToString(pattern);
if (string.IsNullOrEmpty(p))
Expand Down
16 changes: 9 additions & 7 deletions Jint/Native/RegExp/RegExpPrototype.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Text.RegularExpressions;
#pragma warning disable CA1859 // Use concrete types when possible for improved performance -- most of prototype methods return JsValue

using System.Text.RegularExpressions;
using Jint.Collections;
using Jint.Native.Number;
using Jint.Native.Object;
Expand Down Expand Up @@ -139,17 +141,17 @@ private JsValue Replace(JsValue thisObject, JsValue[] arguments)
{
var value = TypeConverter.ToString(replaceValue);
replaceValue = value;
mayHaveNamedCaptures = value.IndexOf('$') != -1;
mayHaveNamedCaptures = value.Contains('$');
}

var flags = TypeConverter.ToString(rx.Get(PropertyFlags));
var global = flags.IndexOf('g') != -1;
var global = flags.Contains('g');

var fullUnicode = false;

if (global)
{
fullUnicode = flags.IndexOf('u') != -1;
fullUnicode = flags.Contains('u');
rx.Set(JsRegExp.PropertyLastIndex, 0, true);
}

Expand Down Expand Up @@ -527,7 +529,7 @@ private JsValue Split(JsValue thisObject, JsValue[] arguments)
return SplitSlow(s, splitter, unicodeMatching, lengthA, lim);
}

private JsValue SplitSlow(string s, ObjectInstance splitter, bool unicodeMatching, uint lengthA, long lim)
private JsArray SplitSlow(string s, ObjectInstance splitter, bool unicodeMatching, uint lengthA, long lim)
{
var a = _realm.Intrinsics.Array.ArrayCreate(0);
ulong previousStringIndex = 0;
Expand Down Expand Up @@ -684,13 +686,13 @@ private JsValue Match(JsValue thisObject, JsValue[] arguments)

var s = TypeConverter.ToString(arguments.At(0));
var flags = TypeConverter.ToString(rx.Get(PropertyFlags));
var global = flags.IndexOf('g') != -1;
var global = flags.Contains('g');
if (!global)
{
return RegExpExec(rx, s);
}

var fullUnicode = flags.IndexOf('u') != -1;
var fullUnicode = flags.Contains('u');
rx.Set(JsRegExp.PropertyLastIndex, JsNumber.PositiveZero, true);

if (!fullUnicode
Expand Down
2 changes: 2 additions & 0 deletions Jint/Native/Set/SetPrototype.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#pragma warning disable CA1859 // Use concrete types when possible for improved performance -- most of prototype methods return JsValue

using Jint.Collections;
using Jint.Native.Object;
using Jint.Native.Symbol;
Expand Down
2 changes: 1 addition & 1 deletion Jint/Native/ShadowRealm/ShadowRealm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ private static JsValue GetWrappedValue(Realm throwerRealm, Realm callerRealm, Js
/// <summary>
/// https://tc39.es/proposal-shadowrealm/#sec-wrappedfunctioncreate
/// </summary>
private static JsValue WrappedFunctionCreate(Realm throwerRealm, Realm callerRealm, ObjectInstance target)
private static WrappedFunction WrappedFunctionCreate(Realm throwerRealm, Realm callerRealm, ObjectInstance target)
{
var wrapped = new WrappedFunction(callerRealm.GlobalEnv._engine, callerRealm, target);
try
Expand Down
4 changes: 3 additions & 1 deletion Jint/Native/String/StringConstructor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Jint.Collections;
#pragma warning disable CA1859 // Use concrete types when possible for improved performance -- most of prototype methods return JsValue

using Jint.Collections;
using Jint.Native.Array;
using Jint.Native.Function;
using Jint.Native.Object;
Expand Down
2 changes: 2 additions & 0 deletions Jint/Native/String/StringPrototype.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#pragma warning disable CA1859 // Use concrete types when possible for improved performance -- most of prototype methods return JsValue

using System.Globalization;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
Expand Down
2 changes: 2 additions & 0 deletions Jint/Native/Symbol/SymbolConstructor.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#pragma warning disable CA1859 // Use concrete types when possible for improved performance -- most of constructor methods return JsValue

using Jint.Collections;
using Jint.Native.Function;
using Jint.Native.Object;
Expand Down
2 changes: 2 additions & 0 deletions Jint/Native/Symbol/SymbolPrototype.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#pragma warning disable CA1859 // Use concrete types when possible for improved performance -- most of prototype methods return JsValue

using Jint.Collections;
using Jint.Native.Object;
using Jint.Runtime;
Expand Down
2 changes: 2 additions & 0 deletions Jint/Native/TypedArray/IntrinsicTypedArrayConstructor.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#pragma warning disable CA1859 // Use concrete types when possible for improved performance -- most of constructor methods return JsValue

using Jint.Collections;
using Jint.Native.Object;
using Jint.Native.Symbol;
Expand Down
2 changes: 2 additions & 0 deletions Jint/Native/TypedArray/IntrinsicTypedArrayPrototype.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#pragma warning disable CA1859 // Use concrete types when possible for improved performance -- most of prototype methods return JsValue

using System.Linq;
using Jint.Collections;
using Jint.Native.Array;
Expand Down
2 changes: 2 additions & 0 deletions Jint/Native/WeakMap/WeakMapPrototype.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#pragma warning disable CA1859 // Use concrete types when possible for improved performance -- most of prototype methods return JsValue

using Jint.Collections;
using Jint.Native.Object;
using Jint.Native.Symbol;
Expand Down
2 changes: 2 additions & 0 deletions Jint/Native/WeakSet/WeakSetPrototype.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#pragma warning disable CA1859 // Use concrete types when possible for improved performance -- most of prototype methods return JsValue

using Jint.Collections;
using Jint.Native.Object;
using Jint.Native.Symbol;
Expand Down
2 changes: 2 additions & 0 deletions Jint/Runtime/CallStack/JintCallStack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,10 @@ public int Push(FunctionInstance functionInstance, JintExpression? expression, i
if (_statistics is not null)
{
#pragma warning disable CA1854
#pragma warning disable CA1864
if (_statistics.ContainsKey(item))
#pragma warning restore CA1854
#pragma warning restore CA1864
{
return ++_statistics[item];
}
Expand Down
Loading

0 comments on commit 6653ec8

Please sign in to comment.