From 6653ec842c0edde682574755a7b3c1f359d824c2 Mon Sep 17 00:00:00 2001 From: Marko Lahma Date: Sat, 18 Nov 2023 18:08:01 +0200 Subject: [PATCH] Code changes to keep NET 8 analyzers happy (#1685) --- Jint/Engine.Modules.cs | 4 ++-- Jint/Extensions/Polyfills.cs | 12 ++++++++++++ Jint/Native/Array/ArrayConstructor.cs | 2 ++ Jint/Native/Array/ArrayPrototype.cs | 2 ++ Jint/Native/ArrayBuffer/ArrayBufferPrototype.cs | 2 ++ Jint/Native/Boolean/BooleanPrototype.cs | 2 +- Jint/Native/DataView/DataViewPrototype.cs | 2 ++ Jint/Native/Date/DateConstructor.cs | 2 ++ Jint/Native/Date/DatePrototype.cs | 2 ++ Jint/Native/Date/MimeKit.cs | 1 + Jint/Native/Function/FunctionConstructor.cs | 6 +++--- Jint/Native/Function/FunctionInstance.Dynamic.cs | 4 ++-- Jint/Native/Function/FunctionPrototype.cs | 2 ++ Jint/Native/Global/GlobalObject.cs | 6 +++--- Jint/Native/Intl/IntlInstance.cs | 2 ++ Jint/Native/Iterator/IteratorInstance.cs | 2 +- Jint/Native/Json/JsonParser.cs | 4 ++-- Jint/Native/Map/MapConstructor.cs | 2 ++ Jint/Native/Map/MapPrototype.cs | 2 ++ Jint/Native/Object/ObjectConstructor.cs | 2 ++ Jint/Native/Object/ObjectPrototype.cs | 2 ++ Jint/Native/Promise/PromiseConstructor.cs | 2 +- Jint/Native/Promise/PromisePrototype.cs | 4 ++-- Jint/Native/Proxy/ProxyConstructor.cs | 2 ++ Jint/Native/Reflect/ReflectInstance.cs | 2 ++ Jint/Native/RegExp/RegExpConstructor.cs | 2 +- Jint/Native/RegExp/RegExpPrototype.cs | 16 +++++++++------- Jint/Native/Set/SetPrototype.cs | 2 ++ Jint/Native/ShadowRealm/ShadowRealm.cs | 2 +- Jint/Native/String/StringConstructor.cs | 4 +++- Jint/Native/String/StringPrototype.cs | 2 ++ Jint/Native/Symbol/SymbolConstructor.cs | 2 ++ Jint/Native/Symbol/SymbolPrototype.cs | 2 ++ .../TypedArray/IntrinsicTypedArrayConstructor.cs | 2 ++ .../TypedArray/IntrinsicTypedArrayPrototype.cs | 2 ++ Jint/Native/WeakMap/WeakMapPrototype.cs | 2 ++ Jint/Native/WeakSet/WeakSetPrototype.cs | 2 ++ Jint/Runtime/CallStack/JintCallStack.cs | 2 ++ Jint/Runtime/Interop/DefaultObjectConverter.cs | 2 +- Jint/Runtime/Interop/NamespaceReference.cs | 2 +- Jint/Runtime/Interop/ObjectWrapper.cs | 2 +- Jint/Runtime/Interop/TypeReference.cs | 6 ++++-- .../Expressions/JintCallExpression.cs | 2 +- .../Expressions/JintMemberExpression.cs | 2 +- .../Expressions/JintObjectExpression.cs | 2 +- Jint/Runtime/Modules/DefaultModuleLoader.cs | 2 +- Jint/Runtime/Modules/ModuleRecord.cs | 2 +- 47 files changed, 102 insertions(+), 37 deletions(-) create mode 100644 Jint/Extensions/Polyfills.cs diff --git a/Jint/Engine.Modules.cs b/Jint/Engine.Modules.cs index 6306424082..d79bc9ae12 100644 --- a/Jint/Engine.Modules.cs +++ b/Jint/Engine.Modules.cs @@ -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); @@ -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); diff --git a/Jint/Extensions/Polyfills.cs b/Jint/Extensions/Polyfills.cs new file mode 100644 index 0000000000..f818922b0f --- /dev/null +++ b/Jint/Extensions/Polyfills.cs @@ -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 +} diff --git a/Jint/Native/Array/ArrayConstructor.cs b/Jint/Native/Array/ArrayConstructor.cs index 52de03cb64..204e0156fc 100644 --- a/Jint/Native/Array/ArrayConstructor.cs +++ b/Jint/Native/Array/ArrayConstructor.cs @@ -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; diff --git a/Jint/Native/Array/ArrayPrototype.cs b/Jint/Native/Array/ArrayPrototype.cs index ff171f6051..f1e16039d6 100644 --- a/Jint/Native/Array/ArrayPrototype.cs +++ b/Jint/Native/Array/ArrayPrototype.cs @@ -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; diff --git a/Jint/Native/ArrayBuffer/ArrayBufferPrototype.cs b/Jint/Native/ArrayBuffer/ArrayBufferPrototype.cs index ae7aab0533..d89f20738e 100644 --- a/Jint/Native/ArrayBuffer/ArrayBufferPrototype.cs +++ b/Jint/Native/ArrayBuffer/ArrayBufferPrototype.cs @@ -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; diff --git a/Jint/Native/Boolean/BooleanPrototype.cs b/Jint/Native/Boolean/BooleanPrototype.cs index 2379426429..303fed71ac 100644 --- a/Jint/Native/Boolean/BooleanPrototype.cs +++ b/Jint/Native/Boolean/BooleanPrototype.cs @@ -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; diff --git a/Jint/Native/DataView/DataViewPrototype.cs b/Jint/Native/DataView/DataViewPrototype.cs index 304de07084..342e539af7 100644 --- a/Jint/Native/DataView/DataViewPrototype.cs +++ b/Jint/Native/DataView/DataViewPrototype.cs @@ -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; diff --git a/Jint/Native/Date/DateConstructor.cs b/Jint/Native/Date/DateConstructor.cs index 144162d420..ac89e19ccb 100644 --- a/Jint/Native/Date/DateConstructor.cs +++ b/Jint/Native/Date/DateConstructor.cs @@ -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; diff --git a/Jint/Native/Date/DatePrototype.cs b/Jint/Native/Date/DatePrototype.cs index 47eeb4399b..68459a1f9e 100644 --- a/Jint/Native/Date/DatePrototype.cs +++ b/Jint/Native/Date/DatePrototype.cs @@ -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; diff --git a/Jint/Native/Date/MimeKit.cs b/Jint/Native/Date/MimeKit.cs index 03e905feba..39d28e075c 100644 --- a/Jint/Native/Date/MimeKit.cs +++ b/Jint/Native/Date/MimeKit.cs @@ -1,4 +1,5 @@ #nullable disable +#pragma warning disable CA1510 namespace Jint.Native.Date; diff --git a/Jint/Native/Function/FunctionConstructor.cs b/Jint/Native/Function/FunctionConstructor.cs index e362f75265..c9637dbed6 100644 --- a/Jint/Native/Function/FunctionConstructor.cs +++ b/Jint/Native/Function/FunctionConstructor.cs @@ -67,7 +67,7 @@ internal FunctionInstance InstantiateFunctionObject( /// /// https://tc39.es/ecma262/#sec-runtime-semantics-instantiateasyncfunctionobject /// - private FunctionInstance InstantiateAsyncFunctionObject( + private ScriptFunctionInstance InstantiateAsyncFunctionObject( JintFunctionDefinition functionDeclaration, EnvironmentRecord env, PrivateEnvironmentRecord? privateEnv) @@ -87,7 +87,7 @@ private FunctionInstance InstantiateAsyncFunctionObject( /// /// https://tc39.es/ecma262/#sec-runtime-semantics-instantiateordinaryfunctionobject /// - private FunctionInstance InstantiateOrdinaryFunctionObject( + private ScriptFunctionInstance InstantiateOrdinaryFunctionObject( JintFunctionDefinition functionDeclaration, EnvironmentRecord env, PrivateEnvironmentRecord? privateEnv) @@ -108,7 +108,7 @@ private FunctionInstance InstantiateOrdinaryFunctionObject( /// /// https://tc39.es/ecma262/#sec-runtime-semantics-instantiategeneratorfunctionobject /// - private FunctionInstance InstantiateGeneratorFunctionObject( + private ScriptFunctionInstance InstantiateGeneratorFunctionObject( JintFunctionDefinition functionDeclaration, EnvironmentRecord scope, PrivateEnvironmentRecord? privateScope) diff --git a/Jint/Native/Function/FunctionInstance.Dynamic.cs b/Jint/Native/Function/FunctionInstance.Dynamic.cs index b3537b833c..57714f8429 100644 --- a/Jint/Native/Function/FunctionInstance.Dynamic.cs +++ b/Jint/Native/Function/FunctionInstance.Dynamic.cs @@ -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"; @@ -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}"; diff --git a/Jint/Native/Function/FunctionPrototype.cs b/Jint/Native/Function/FunctionPrototype.cs index 8bc50f9460..37f1c4b943 100644 --- a/Jint/Native/Function/FunctionPrototype.cs +++ b/Jint/Native/Function/FunctionPrototype.cs @@ -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; diff --git a/Jint/Native/Global/GlobalObject.cs b/Jint/Native/Global/GlobalObject.cs index 383295e18a..5bb0bb41aa 100644 --- a/Jint/Native/Global/GlobalObject.cs +++ b/Jint/Native/Global/GlobalObject.cs @@ -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); } @@ -594,7 +594,7 @@ private static bool IsDigit(char c, int radix, out int result) /// 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; @@ -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); } diff --git a/Jint/Native/Intl/IntlInstance.cs b/Jint/Native/Intl/IntlInstance.cs index 1e7e9f97e2..0853bff8a4 100644 --- a/Jint/Native/Intl/IntlInstance.cs +++ b/Jint/Native/Intl/IntlInstance.cs @@ -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; diff --git a/Jint/Native/Iterator/IteratorInstance.cs b/Jint/Native/Iterator/IteratorInstance.cs index fd8c86ef4e..0aaa57907d 100644 --- a/Jint/Native/Iterator/IteratorInstance.cs +++ b/Jint/Native/Iterator/IteratorInstance.cs @@ -27,7 +27,7 @@ public virtual void Close(CompletionType completion) /// /// https://tc39.es/ecma262/#sec-createiterresultobject /// - private ObjectInstance CreateIterResultObject(JsValue value, bool done) + private IteratorResult CreateIterResultObject(JsValue value, bool done) { return new IteratorResult(_engine, value, JsBoolean.Create(done)); } diff --git a/Jint/Native/Json/JsonParser.cs b/Jint/Native/Json/JsonParser.cs index a1a593f0ee..c0a559b05d 100644 --- a/Jint/Native/Json/JsonParser.cs +++ b/Jint/Native/Json/JsonParser.cs @@ -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) { @@ -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) { diff --git a/Jint/Native/Map/MapConstructor.cs b/Jint/Native/Map/MapConstructor.cs index 26d39f334b..a77d97993e 100644 --- a/Jint/Native/Map/MapConstructor.cs +++ b/Jint/Native/Map/MapConstructor.cs @@ -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; diff --git a/Jint/Native/Map/MapPrototype.cs b/Jint/Native/Map/MapPrototype.cs index ff77ac3f70..2135387e04 100644 --- a/Jint/Native/Map/MapPrototype.cs +++ b/Jint/Native/Map/MapPrototype.cs @@ -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; diff --git a/Jint/Native/Object/ObjectConstructor.cs b/Jint/Native/Object/ObjectConstructor.cs index c40a745bfd..9e5a651221 100644 --- a/Jint/Native/Object/ObjectConstructor.cs +++ b/Jint/Native/Object/ObjectConstructor.cs @@ -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; diff --git a/Jint/Native/Object/ObjectPrototype.cs b/Jint/Native/Object/ObjectPrototype.cs index 9dbaa826df..7b1655397b 100644 --- a/Jint/Native/Object/ObjectPrototype.cs +++ b/Jint/Native/Object/ObjectPrototype.cs @@ -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; diff --git a/Jint/Native/Promise/PromiseConstructor.cs b/Jint/Native/Promise/PromiseConstructor.cs index 56b227b4e6..da3da29b27 100644 --- a/Jint/Native/Promise/PromiseConstructor.cs +++ b/Jint/Native/Promise/PromiseConstructor.cs @@ -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); diff --git a/Jint/Native/Promise/PromisePrototype.cs b/Jint/Native/Promise/PromisePrototype.cs index c81f91c7ef..5150ccebe9 100644 --- a/Jint/Native/Promise/PromisePrototype.cs +++ b/Jint/Native/Promise/PromisePrototype.cs @@ -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); @@ -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); diff --git a/Jint/Native/Proxy/ProxyConstructor.cs b/Jint/Native/Proxy/ProxyConstructor.cs index d06fdcd237..be8e81ec98 100644 --- a/Jint/Native/Proxy/ProxyConstructor.cs +++ b/Jint/Native/Proxy/ProxyConstructor.cs @@ -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; diff --git a/Jint/Native/Reflect/ReflectInstance.cs b/Jint/Native/Reflect/ReflectInstance.cs index 4713fe1516..a12f063ca1 100644 --- a/Jint/Native/Reflect/ReflectInstance.cs +++ b/Jint/Native/Reflect/ReflectInstance.cs @@ -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; diff --git a/Jint/Native/RegExp/RegExpConstructor.cs b/Jint/Native/RegExp/RegExpConstructor.cs index 9e0a174377..1c1db22dbc 100644 --- a/Jint/Native/RegExp/RegExpConstructor.cs +++ b/Jint/Native/RegExp/RegExpConstructor.cs @@ -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)) diff --git a/Jint/Native/RegExp/RegExpPrototype.cs b/Jint/Native/RegExp/RegExpPrototype.cs index 7b00c2dcd1..ab1d50ff82 100644 --- a/Jint/Native/RegExp/RegExpPrototype.cs +++ b/Jint/Native/RegExp/RegExpPrototype.cs @@ -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; @@ -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); } @@ -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; @@ -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 diff --git a/Jint/Native/Set/SetPrototype.cs b/Jint/Native/Set/SetPrototype.cs index 5f97ca8c0b..11e0753c52 100644 --- a/Jint/Native/Set/SetPrototype.cs +++ b/Jint/Native/Set/SetPrototype.cs @@ -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; diff --git a/Jint/Native/ShadowRealm/ShadowRealm.cs b/Jint/Native/ShadowRealm/ShadowRealm.cs index cc3db89dca..116af5c0c8 100644 --- a/Jint/Native/ShadowRealm/ShadowRealm.cs +++ b/Jint/Native/ShadowRealm/ShadowRealm.cs @@ -210,7 +210,7 @@ private static JsValue GetWrappedValue(Realm throwerRealm, Realm callerRealm, Js /// /// https://tc39.es/proposal-shadowrealm/#sec-wrappedfunctioncreate /// - 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 diff --git a/Jint/Native/String/StringConstructor.cs b/Jint/Native/String/StringConstructor.cs index 28caa2cc20..5a30c3df72 100644 --- a/Jint/Native/String/StringConstructor.cs +++ b/Jint/Native/String/StringConstructor.cs @@ -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; diff --git a/Jint/Native/String/StringPrototype.cs b/Jint/Native/String/StringPrototype.cs index 408db21452..2beeece784 100644 --- a/Jint/Native/String/StringPrototype.cs +++ b/Jint/Native/String/StringPrototype.cs @@ -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; diff --git a/Jint/Native/Symbol/SymbolConstructor.cs b/Jint/Native/Symbol/SymbolConstructor.cs index 0252db8164..44dc27d33e 100644 --- a/Jint/Native/Symbol/SymbolConstructor.cs +++ b/Jint/Native/Symbol/SymbolConstructor.cs @@ -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; diff --git a/Jint/Native/Symbol/SymbolPrototype.cs b/Jint/Native/Symbol/SymbolPrototype.cs index 7c29ecd05d..97e3522102 100644 --- a/Jint/Native/Symbol/SymbolPrototype.cs +++ b/Jint/Native/Symbol/SymbolPrototype.cs @@ -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; diff --git a/Jint/Native/TypedArray/IntrinsicTypedArrayConstructor.cs b/Jint/Native/TypedArray/IntrinsicTypedArrayConstructor.cs index 9b019a099c..7695d36029 100644 --- a/Jint/Native/TypedArray/IntrinsicTypedArrayConstructor.cs +++ b/Jint/Native/TypedArray/IntrinsicTypedArrayConstructor.cs @@ -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; diff --git a/Jint/Native/TypedArray/IntrinsicTypedArrayPrototype.cs b/Jint/Native/TypedArray/IntrinsicTypedArrayPrototype.cs index 039b84a97d..dff4978054 100644 --- a/Jint/Native/TypedArray/IntrinsicTypedArrayPrototype.cs +++ b/Jint/Native/TypedArray/IntrinsicTypedArrayPrototype.cs @@ -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; diff --git a/Jint/Native/WeakMap/WeakMapPrototype.cs b/Jint/Native/WeakMap/WeakMapPrototype.cs index 528328567f..822854c5b0 100644 --- a/Jint/Native/WeakMap/WeakMapPrototype.cs +++ b/Jint/Native/WeakMap/WeakMapPrototype.cs @@ -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; diff --git a/Jint/Native/WeakSet/WeakSetPrototype.cs b/Jint/Native/WeakSet/WeakSetPrototype.cs index 43e8ea2c02..15e8e038bb 100644 --- a/Jint/Native/WeakSet/WeakSetPrototype.cs +++ b/Jint/Native/WeakSet/WeakSetPrototype.cs @@ -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; diff --git a/Jint/Runtime/CallStack/JintCallStack.cs b/Jint/Runtime/CallStack/JintCallStack.cs index 7c67db4bf1..d6a234791d 100644 --- a/Jint/Runtime/CallStack/JintCallStack.cs +++ b/Jint/Runtime/CallStack/JintCallStack.cs @@ -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]; } diff --git a/Jint/Runtime/Interop/DefaultObjectConverter.cs b/Jint/Runtime/Interop/DefaultObjectConverter.cs index f94fa7bf10..e7cc6654d4 100644 --- a/Jint/Runtime/Interop/DefaultObjectConverter.cs +++ b/Jint/Runtime/Interop/DefaultObjectConverter.cs @@ -162,7 +162,7 @@ private static bool TryConvertConvertible(Engine engine, IConvertible convertibl return result is not null; } - private static JsValue ConvertArray(Engine e, object v) + private static JsArray ConvertArray(Engine e, object v) { var array = (Array) v; var arrayLength = (uint) array.Length; diff --git a/Jint/Runtime/Interop/NamespaceReference.cs b/Jint/Runtime/Interop/NamespaceReference.cs index 4a58c21f67..46dfe9515a 100644 --- a/Jint/Runtime/Interop/NamespaceReference.cs +++ b/Jint/Runtime/Interop/NamespaceReference.cs @@ -117,7 +117,7 @@ public JsValue GetPath(string path) return TypeReference.CreateTypeReference(_engine, type); } - var lastPeriodPos = path.LastIndexOf(".", StringComparison.Ordinal); + var lastPeriodPos = path.LastIndexOf('.'); var trimPath = path.Substring(0, lastPeriodPos); type = GetType(assembly, trimPath); if (type != null) diff --git a/Jint/Runtime/Interop/ObjectWrapper.cs b/Jint/Runtime/Interop/ObjectWrapper.cs index 2fc549d7c1..ec7a127a5e 100644 --- a/Jint/Runtime/Interop/ObjectWrapper.cs +++ b/Jint/Runtime/Interop/ObjectWrapper.cs @@ -290,7 +290,7 @@ private static JsValue Iterator(JsValue thisObject, JsValue[] arguments) : new EnumerableIterator(wrapper._engine, (IEnumerable) wrapper.Target); } - private static JsValue GetLength(JsValue thisObject, JsValue[] arguments) + private static JsNumber GetLength(JsValue thisObject, JsValue[] arguments) { var wrapper = (ObjectWrapper) thisObject; return JsNumber.Create((int) (wrapper._typeDescriptor.LengthProperty?.GetValue(wrapper.Target) ?? 0)); diff --git a/Jint/Runtime/Interop/TypeReference.cs b/Jint/Runtime/Interop/TypeReference.cs index ea1a990eab..40f14cbbb5 100644 --- a/Jint/Runtime/Interop/TypeReference.cs +++ b/Jint/Runtime/Interop/TypeReference.cs @@ -327,7 +327,7 @@ private static ReflectionAccessor ResolveMemberAccessor(Engine engine, Type type public object Target => ReferenceType; - private static JsValue HasInstance(JsValue thisObject, JsValue[] arguments) + private static JsBoolean HasInstance(JsValue thisObject, JsValue[] arguments) { var typeReference = thisObject as TypeReference; var other = arguments.At(0); @@ -346,7 +346,9 @@ private static JsValue HasInstance(JsValue thisObject, JsValue[] arguments) _ => null }; - return derivedType != null && baseType != null && (derivedType == baseType || derivedType.IsSubclassOf(baseType)); + return derivedType != null && baseType != null && (derivedType == baseType || derivedType.IsSubclassOf(baseType)) + ? JsBoolean.True + : JsBoolean.False; } public override string ToString() diff --git a/Jint/Runtime/Interpreter/Expressions/JintCallExpression.cs b/Jint/Runtime/Interpreter/Expressions/JintCallExpression.cs index 6f0ba09c61..53c8e1241f 100644 --- a/Jint/Runtime/Interpreter/Expressions/JintCallExpression.cs +++ b/Jint/Runtime/Interpreter/Expressions/JintCallExpression.cs @@ -251,7 +251,7 @@ private JsValue HandleEval(EvaluationContext context, JsValue func, Engine engin return value; } - private JsValue SuperCall(EvaluationContext context) + private ObjectInstance SuperCall(EvaluationContext context) { var engine = context.Engine; var thisEnvironment = (FunctionEnvironmentRecord) engine.ExecutionContext.GetThisEnvironment(); diff --git a/Jint/Runtime/Interpreter/Expressions/JintMemberExpression.cs b/Jint/Runtime/Interpreter/Expressions/JintMemberExpression.cs index 22229a0454..29251b90a0 100644 --- a/Jint/Runtime/Interpreter/Expressions/JintMemberExpression.cs +++ b/Jint/Runtime/Interpreter/Expressions/JintMemberExpression.cs @@ -140,7 +140,7 @@ protected override object EvaluateInternal(EvaluationContext context) /// /// https://tc39.es/ecma262/#sec-makeprivatereference /// - private static object MakePrivateReference(Engine engine, JsValue baseValue, JsValue privateIdentifier) + private static Reference MakePrivateReference(Engine engine, JsValue baseValue, JsValue privateIdentifier) { var privEnv = engine.ExecutionContext.PrivateEnvironment; var privateName = privEnv!.ResolvePrivateIdentifier(privateIdentifier.ToString()); diff --git a/Jint/Runtime/Interpreter/Expressions/JintObjectExpression.cs b/Jint/Runtime/Interpreter/Expressions/JintObjectExpression.cs index 1231f79537..9b7c3d32e7 100644 --- a/Jint/Runtime/Interpreter/Expressions/JintObjectExpression.cs +++ b/Jint/Runtime/Interpreter/Expressions/JintObjectExpression.cs @@ -134,7 +134,7 @@ protected override object EvaluateInternal(EvaluationContext context) /// /// Version that can safely build plain object with only normal init/data fields fast. /// - private object BuildObjectFast(EvaluationContext context) + private JsObject BuildObjectFast(EvaluationContext context) { var obj = new JsObject(context.Engine); var properties = new PropertyDictionary(_properties.Length, checkExistingKeys: true); diff --git a/Jint/Runtime/Modules/DefaultModuleLoader.cs b/Jint/Runtime/Modules/DefaultModuleLoader.cs index ee6fbfa5c7..b019f8c54e 100644 --- a/Jint/Runtime/Modules/DefaultModuleLoader.cs +++ b/Jint/Runtime/Modules/DefaultModuleLoader.cs @@ -151,6 +151,6 @@ public Module LoadModule(Engine engine, ResolvedSpecifier resolved) private static bool IsRelative(string specifier) { - return specifier.StartsWith(".", StringComparison.Ordinal) || specifier.StartsWith("/", StringComparison.Ordinal); + return specifier.StartsWith('.') || specifier.StartsWith('/'); } } diff --git a/Jint/Runtime/Modules/ModuleRecord.cs b/Jint/Runtime/Modules/ModuleRecord.cs index 21b27460c0..043efbb890 100644 --- a/Jint/Runtime/Modules/ModuleRecord.cs +++ b/Jint/Runtime/Modules/ModuleRecord.cs @@ -67,7 +67,7 @@ public static ObjectInstance GetModuleNamespace(ModuleRecord module) /// /// https://tc39.es/ecma262/#sec-modulenamespacecreate /// - private static ObjectInstance CreateModuleNamespace(ModuleRecord module, List unambiguousNames) + private static ModuleNamespace CreateModuleNamespace(ModuleRecord module, List unambiguousNames) { var m = new ModuleNamespace(module._engine, module, unambiguousNames); module._namespace = m;