浏览代码

Enable nullable reference types by default (#1237)

Marko Lahma 3 年之前
父节点
当前提交
97e481fc4e
共有 100 个文件被更改,包括 487 次插入479 次删除
  1. 1 1
      Jint/AssemblyInfoExtras.cs
  2. 3 1
      Jint/Collections/DictionarySlim.cs
  3. 2 0
      Jint/Collections/HybridDictionary.cs
  4. 2 0
      Jint/Collections/ListDictionary.cs
  5. 1 1
      Jint/Collections/PropertyDictionary.cs
  6. 0 2
      Jint/Collections/RefStack.cs
  7. 3 1
      Jint/Collections/StringDictionarySlim.cs
  8. 1 1
      Jint/Collections/SymbolDictionary.cs
  9. 1 1
      Jint/Constraints/CancellationConstraint.cs
  10. 1 1
      Jint/Constraints/ConstraintsOptionsExtensions.cs
  11. 1 1
      Jint/Constraints/MaxStatements.cs
  12. 2 2
      Jint/Constraints/MemoryLimit.cs
  13. 1 1
      Jint/Constraints/TimeConstraint.cs
  14. 5 5
      Jint/Constraints/TimeConstraint2.cs
  15. 1 1
      Jint/DeclarationBindingType.cs
  16. 4 6
      Jint/Engine.Modules.cs
  17. 52 50
      Jint/Engine.cs
  18. 2 4
      Jint/EsprimaExtensions.cs
  19. 5 0
      Jint/Extensions/JavascriptExtensions.cs
  20. 9 8
      Jint/Extensions/ReflectionExtensions.cs
  21. 27 27
      Jint/HoistingScope.cs
  22. 1 1
      Jint/IConstraint.cs
  23. 1 0
      Jint/Jint.csproj
  24. 10 10
      Jint/JsValueExtensions.cs
  25. 0 2
      Jint/ModuleBuilder.cs
  26. 0 2
      Jint/Native/AggregateError/AggregateErrorConstructor.cs
  27. 0 2
      Jint/Native/AggregateError/AggregateErrorPrototype.cs
  28. 8 8
      Jint/Native/Argument/ArgumentsInstance.cs
  29. 7 7
      Jint/Native/Array/ArrayConstructor.cs
  30. 47 38
      Jint/Native/Array/ArrayInstance.cs
  31. 5 6
      Jint/Native/Array/ArrayIteratorPrototype.cs
  32. 5 5
      Jint/Native/Array/ArrayOperations.cs
  33. 22 22
      Jint/Native/Array/ArrayPrototype.cs
  34. 1 1
      Jint/Native/ArrayBuffer/ArrayBufferConstructor.cs
  35. 5 5
      Jint/Native/ArrayBuffer/ArrayBufferInstance.cs
  36. 1 1
      Jint/Native/ArrayBuffer/ArrayBufferOrder.cs
  37. 1 1
      Jint/Native/ArrayBuffer/ArrayBufferPrototype.cs
  38. 5 6
      Jint/Native/BigInt/BigIntConstructor.cs
  39. 4 9
      Jint/Native/BigInt/BigIntInstance.cs
  40. 1 1
      Jint/Native/BigInt/BigIntPrototype.cs
  41. 4 5
      Jint/Native/Boolean/BooleanConstructor.cs
  42. 3 8
      Jint/Native/Boolean/BooleanInstance.cs
  43. 3 4
      Jint/Native/Boolean/BooleanPrototype.cs
  44. 1 1
      Jint/Native/DataView/DataViewConstructor.cs
  45. 2 2
      Jint/Native/DataView/DataViewInstance.cs
  46. 6 6
      Jint/Native/DataView/DataViewPrototype.cs
  47. 2 2
      Jint/Native/Date/DateConstructor.cs
  48. 1 1
      Jint/Native/Date/DateInstance.cs
  49. 1 1
      Jint/Native/Date/DatePrototype.cs
  50. 2 2
      Jint/Native/Error/ErrorConstructor.cs
  51. 0 2
      Jint/Native/Error/ErrorInstance.cs
  52. 1 1
      Jint/Native/Error/ErrorPrototype.cs
  53. 2 2
      Jint/Native/Function/BindFunctionInstance.cs
  54. 0 2
      Jint/Native/Function/ClassDefinition.cs
  55. 1 1
      Jint/Native/Function/ConstructorKind.cs
  56. 5 5
      Jint/Native/Function/EvalFunctionInstance.cs
  57. 9 9
      Jint/Native/Function/FunctionConstructor.cs
  58. 17 18
      Jint/Native/Function/FunctionInstance.cs
  59. 1 1
      Jint/Native/Function/FunctionKind.cs
  60. 1 1
      Jint/Native/Function/FunctionPrototype.cs
  61. 1 1
      Jint/Native/Function/FunctionThisMode.cs
  62. 5 5
      Jint/Native/Function/ScriptFunctionInstance.cs
  63. 1 1
      Jint/Native/Function/ThrowTypeError.cs
  64. 1 1
      Jint/Native/Generator/GeneratorKind.cs
  65. 56 56
      Jint/Native/Global/GlobalObject.cs
  66. 1 1
      Jint/Native/ICallable.cs
  67. 1 1
      Jint/Native/IConstructor.cs
  68. 1 1
      Jint/Native/IPrimitiveInstance.cs
  69. 1 1
      Jint/Native/Iterator/ArrayIteratorType.cs
  70. 8 7
      Jint/Native/Iterator/IteratorInstance.cs
  71. 2 2
      Jint/Native/Iterator/IteratorProtocol.cs
  72. 3 3
      Jint/Native/Iterator/IteratorPrototype.cs
  73. 2 2
      Jint/Native/Iterator/IteratorResult.cs
  74. 2 2
      Jint/Native/JsBigInt.cs
  75. 1 3
      Jint/Native/JsBoolean.cs
  76. 3 5
      Jint/Native/JsNull.cs
  77. 1 3
      Jint/Native/JsNumber.cs
  78. 2 4
      Jint/Native/JsString.cs
  79. 3 3
      Jint/Native/JsSymbol.cs
  80. 4 4
      Jint/Native/JsUndefined.cs
  81. 14 16
      Jint/Native/JsValue.cs
  82. 1 1
      Jint/Native/Json/JsonInstance.cs
  83. 17 17
      Jint/Native/Json/JsonParser.cs
  84. 6 5
      Jint/Native/Json/JsonSerializer.cs
  85. 3 3
      Jint/Native/Map/MapConstructor.cs
  86. 3 2
      Jint/Native/Map/MapInstance.cs
  87. 1 1
      Jint/Native/Map/MapIteratorPrototype.cs
  88. 2 2
      Jint/Native/Map/MapPrototype.cs
  89. 2 2
      Jint/Native/Math/MathInstance.cs
  90. 2 2
      Jint/Native/Null.cs
  91. 2 0
      Jint/Native/Number/Dtoa/Bignum.cs
  92. 2 0
      Jint/Native/Number/Dtoa/BignumDtoa.cs
  93. 3 1
      Jint/Native/Number/Dtoa/CachePowers.cs
  94. 3 1
      Jint/Native/Number/Dtoa/DiyFp.cs
  95. 3 1
      Jint/Native/Number/Dtoa/DoubleHelper.cs
  96. 3 1
      Jint/Native/Number/Dtoa/DtoaBuilder.cs
  97. 2 0
      Jint/Native/Number/Dtoa/DtoaMode.cs
  98. 3 1
      Jint/Native/Number/Dtoa/DtoaNumberFormatter.cs
  99. 3 1
      Jint/Native/Number/Dtoa/FastDtoa.cs
  100. 3 1
      Jint/Native/Number/Dtoa/NumberExtensions.cs

+ 1 - 1
Jint/AssemblyInfoExtras.cs

@@ -1,4 +1,4 @@
-using System.Runtime.CompilerServices;
+using System.Runtime.CompilerServices;
 
 [assembly: InternalsVisibleTo("Jint.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100bf2553c9f214cb21f1f64ed62cadad8fe4f2fa11322a5dfa1d650743145c6085aba05b145b29867af656e0bb9bfd32f5d0deb1668263a38233e7e8e5bad1a3c6edd3f2ec6c512668b4aa797283101444628650949641b4f7cb16707efba542bb754afe87ce956f3a5d43f450d14364eb9571cbf213d1061852fb9dd47a6c05c4")]
 [assembly: InternalsVisibleTo("Jint.Tests.Test262, PublicKey=0024000004800000940000000602000000240000525341310004000001000100bf2553c9f214cb21f1f64ed62cadad8fe4f2fa11322a5dfa1d650743145c6085aba05b145b29867af656e0bb9bfd32f5d0deb1668263a38233e7e8e5bad1a3c6edd3f2ec6c512668b4aa797283101444628650949641b4f7cb16707efba542bb754afe87ce956f3a5d43f450d14364eb9571cbf213d1061852fb9dd47a6c05c4")]

+ 3 - 1
Jint/Collections/DictionarySlim.cs

@@ -1,4 +1,6 @@
-// Licensed to the .NET Foundation under one or more agreements.
+#nullable disable
+
+// Licensed to the .NET Foundation under one or more agreements.
 // The .NET Foundation licenses this file to you under the MIT license.
 // See the LICENSE file in the project root for more information.
 

+ 2 - 0
Jint/Collections/HybridDictionary.cs

@@ -1,3 +1,5 @@
+#nullable disable
+
 using System.Collections;
 using System.Runtime.CompilerServices;
 

+ 2 - 0
Jint/Collections/ListDictionary.cs

@@ -1,3 +1,5 @@
+#nullable disable
+
 using System.Collections;
 using System.Runtime.CompilerServices;
 using Jint.Runtime;

+ 1 - 1
Jint/Collections/PropertyDictionary.cs

@@ -12,4 +12,4 @@ namespace Jint.Collections
         {
         }
     }
-}
+}

+ 0 - 2
Jint/Collections/RefStack.cs

@@ -1,5 +1,3 @@
-#nullable enable
-
 using System.Collections;
 using System.Diagnostics.CodeAnalysis;
 using System.Runtime.CompilerServices;

+ 3 - 1
Jint/Collections/StringDictionarySlim.cs

@@ -1,4 +1,6 @@
-// Licensed to the .NET Foundation under one or more agreements.
+#nullable disable
+
+// Licensed to the .NET Foundation under one or more agreements.
 // The .NET Foundation licenses this file to you under the MIT license.
 // See the LICENSE file in the project root for more information.
 

+ 1 - 1
Jint/Collections/SymbolDictionary.cs

@@ -13,4 +13,4 @@ namespace Jint.Collections
         {
         }
     }
-}
+}

+ 1 - 1
Jint/Constraints/CancellationConstraint.cs

@@ -1,4 +1,4 @@
-using Jint.Runtime;
+using Jint.Runtime;
 using System.Threading;
 
 namespace Jint.Constraints

+ 1 - 1
Jint/Constraints/ConstraintsOptionsExtensions.cs

@@ -1,4 +1,4 @@
-using System.Threading;
+using System.Threading;
 using Jint.Constraints;
 
 namespace Jint

+ 1 - 1
Jint/Constraints/MaxStatements.cs

@@ -1,4 +1,4 @@
-using Jint.Runtime;
+using Jint.Runtime;
 
 namespace Jint.Constraints
 {

+ 2 - 2
Jint/Constraints/MemoryLimit.cs

@@ -1,10 +1,10 @@
-using Jint.Runtime;
+using Jint.Runtime;
 
 namespace Jint.Constraints
 {
     internal sealed class MemoryLimit : IConstraint
     {
-        private static readonly Func<long> GetAllocatedBytesForCurrentThread;
+        private static readonly Func<long>? GetAllocatedBytesForCurrentThread;
         private readonly long _memoryLimit;
         private long _initialMemoryUsage;
 

+ 1 - 1
Jint/Constraints/TimeConstraint.cs

@@ -1,4 +1,4 @@
-using Jint.Runtime;
+using Jint.Runtime;
 
 namespace Jint.Constraints
 {

+ 5 - 5
Jint/Constraints/TimeConstraint2.cs

@@ -1,4 +1,4 @@
-using Jint.Runtime;
+using Jint.Runtime;
 using System.Threading;
 
 namespace Jint.Constraints
@@ -6,7 +6,7 @@ namespace Jint.Constraints
     internal sealed class TimeConstraint2 : IConstraint
     {
         private readonly TimeSpan _timeout;
-        private CancellationTokenSource cts;
+        private CancellationTokenSource? _cts;
 
         public TimeConstraint2(TimeSpan timeout)
         {
@@ -15,7 +15,7 @@ namespace Jint.Constraints
 
         public void Check()
         {
-            if (cts.IsCancellationRequested)
+            if (_cts?.IsCancellationRequested == true)
             {
                 ExceptionHelper.ThrowTimeoutException();
             }
@@ -23,12 +23,12 @@ namespace Jint.Constraints
 
         public void Reset()
         {
-            cts?.Dispose();
+            _cts?.Dispose();
 
             // This cancellation token source is very likely not disposed property, but it only allocates a timer, so not a big deal.
             // But using the cancellation token source is faster because we do not have to check the current time for each statement,
             // which means less system calls.
-            cts = new CancellationTokenSource(_timeout);
+            _cts = new CancellationTokenSource(_timeout);
         }
     }
 }

+ 1 - 1
Jint/DeclarationBindingType.cs

@@ -1,4 +1,4 @@
-namespace Jint
+namespace Jint
 {
     public enum DeclarationBindingType
     {

+ 4 - 6
Jint/Engine.Modules.cs

@@ -1,6 +1,4 @@
-#nullable enable
-
-using Esprima;
+using Esprima;
 using Jint.Native;
 using Jint.Native.Object;
 using Jint.Native.Promise;
@@ -12,7 +10,7 @@ namespace Jint
 {
     public partial class Engine
     {
-        internal IModuleLoader ModuleLoader { get; set; }
+        internal IModuleLoader ModuleLoader { get; set; } = null!;
 
         private readonly Dictionary<string, ModuleRecord> _modules = new();
         private readonly Dictionary<string, ModuleBuilder> _builders = new();
@@ -140,7 +138,7 @@ namespace Jint
             {
                 if (ownsContext)
                 {
-                    _activeEvaluationContext = null;
+                    _activeEvaluationContext = null!;
                 }
             }
 
@@ -151,7 +149,7 @@ namespace Jint
             }
             else if (promise.State == PromiseState.Rejected)
             {
-                ExceptionHelper.ThrowJavaScriptException(this, promise.Value, new Completion(CompletionType.Throw, promise.Value, null, new Location(new Position(), new Position(), specifier)));
+                ExceptionHelper.ThrowJavaScriptException(this, promise.Value, new Completion(CompletionType.Throw, promise.Value!, null, new Location(new Position(), new Position(), specifier)));
             }
             else if (promise.State != PromiseState.Fulfilled)
             {

+ 52 - 50
Jint/Engine.cs

@@ -31,15 +31,15 @@ namespace Jint
 
         private readonly ExecutionContextStack _executionContexts;
         private JsValue _completionValue = JsValue.Undefined;
-        internal EvaluationContext _activeEvaluationContext;
+        internal EvaluationContext? _activeEvaluationContext;
 
         private readonly EventLoop _eventLoop = new();
 
         // lazy properties
-        private DebugHandler _debugHandler;
+        private DebugHandler? _debugHandler;
 
         // cached access
-        internal readonly IObjectConverter[] _objectConverters;
+        internal readonly IObjectConverter[]? _objectConverters;
         private readonly IConstraint[] _constraints;
         internal readonly bool _isDebugMode;
         internal bool _isStrict;
@@ -49,10 +49,10 @@ namespace Jint
         internal readonly JsValueArrayPool _jsValueArrayPool;
         internal readonly ExtensionMethodCache _extensionMethods;
 
-        public ITypeConverter ClrTypeConverter { get; internal set; }
+        public ITypeConverter ClrTypeConverter { get; internal set; } = null!;
 
         // cache of types used when resolving CLR type names
-        internal readonly Dictionary<string, Type> TypeCache = new();
+        internal readonly Dictionary<string, Type?> TypeCache = new();
 
         // cache for already wrapped CLR objects to keep object identity
         internal readonly ConditionalWeakTable<object, ObjectWrapper> _objectWrapperCache = new();
@@ -60,20 +60,20 @@ namespace Jint
         internal readonly JintCallStack CallStack;
 
         // needed in initial engine setup, for example CLR function construction
-        internal Intrinsics _originalIntrinsics;
-        internal Host _host;
+        internal Intrinsics _originalIntrinsics = null!;
+        internal Host _host = null!;
 
         /// <summary>
         /// Constructs a new engine instance.
         /// </summary>
-        public Engine() : this((Action<Options>) null)
+        public Engine() : this((Action<Options>?) null)
         {
         }
 
         /// <summary>
         /// Constructs a new engine instance and allows customizing options.
         /// </summary>
-        public Engine(Action<Options> options)
+        public Engine(Action<Options>? options)
             : this((engine, opts) => options?.Invoke(opts))
         {
         }
@@ -133,7 +133,7 @@ namespace Jint
 
         // temporary state for realm so that we can easily pass it to functions while still not
         // having a proper execution context established
-        internal Realm _realmInConstruction;
+        internal Realm? _realmInConstruction;
 
         public Realm Realm => _realmInConstruction ?? ExecutionContext.Realm;
 
@@ -155,7 +155,7 @@ namespace Jint
             EnvironmentRecord lexicalEnvironment,
             EnvironmentRecord variableEnvironment,
             Realm realm,
-            PrivateEnvironmentRecord privateEnvironment)
+            PrivateEnvironmentRecord? privateEnvironment)
         {
             var context = new ExecutionContext(
                 null,
@@ -293,7 +293,7 @@ namespace Jint
                 Completion result;
                 try
                 {
-                    result = list.Execute(_activeEvaluationContext);
+                    result = list.Execute(_activeEvaluationContext!);
                 }
                 catch
                 {
@@ -374,7 +374,7 @@ namespace Jint
             }
         }
 
-        internal void RunBeforeExecuteStatementChecks(Statement statement)
+        internal void RunBeforeExecuteStatementChecks(Statement? statement)
         {
             // Avoid allocating the enumerator because we run this loop very often.
             foreach (var constraint in _constraints)
@@ -449,7 +449,7 @@ namespace Jint
                 {
                     // check if we are accessing a string, boxing operation can be costly to do index access
                     // we have good chance to have fast path with integer or string indexer
-                    ObjectInstance o = null;
+                    ObjectInstance? o = null;
                     if ((property._type & (InternalTypes.String | InternalTypes.Integer)) != 0
                         && baseValue is JsString s
                         && TryHandleStringValue(property, s, ref o, out var jsValue))
@@ -473,7 +473,7 @@ namespace Jint
                         return desc.Value;
                     }
 
-                    var getter = desc.Get;
+                    var getter = desc.Get!;
                     if (getter.IsUndefined())
                     {
                         return Undefined.Instance;
@@ -500,7 +500,7 @@ namespace Jint
             return bindingValue;
         }
 
-        private bool TryHandleStringValue(JsValue property, JsString s, ref ObjectInstance o, out JsValue jsValue)
+        private bool TryHandleStringValue(JsValue property, JsString s, ref ObjectInstance? o, out JsValue jsValue)
         {
             if (property == CommonProperties.Length)
             {
@@ -587,7 +587,7 @@ namespace Jint
         /// <param name="thisObj">The this value inside the function call.</param>
         /// <param name="arguments">The arguments of the function call.</param>
         /// <returns>The value returned by the function call.</returns>
-        public JsValue Invoke(string propertyName, object thisObj, object[] arguments)
+        public JsValue Invoke(string propertyName, object? thisObj, object[] arguments)
         {
             var value = GetValue(propertyName);
 
@@ -612,7 +612,7 @@ namespace Jint
         /// <param name="thisObj">The this value inside the function call.</param>
         /// <param name="arguments">The arguments of the function call.</param>
         /// <returns>The value returned by the function call.</returns>
-        public JsValue Invoke(JsValue value, object thisObj, object[] arguments)
+        public JsValue Invoke(JsValue value, object? thisObj, object[] arguments)
         {
             var callable = value as ICallable;
             if (callable is null)
@@ -656,7 +656,7 @@ namespace Jint
             {
                 if (ownsContext)
                 {
-                    _activeEvaluationContext = null;
+                    _activeEvaluationContext = null!;
                 }
                 _isStrict = oldStrict;
                 ResetConstraints();
@@ -685,7 +685,7 @@ namespace Jint
             {
                 if (ownsContext)
                 {
-                    _activeEvaluationContext = null;
+                    _activeEvaluationContext = null!;
                 }
             }
         }
@@ -711,7 +711,7 @@ namespace Jint
         /// <summary>
         /// Gets the last evaluated <see cref="Node"/>.
         /// </summary>
-        internal Node GetLastSyntaxNode()
+        internal Node? GetLastSyntaxNode()
         {
             return _activeEvaluationContext?.LastSyntaxNode;
         }
@@ -732,13 +732,13 @@ namespace Jint
         /// <summary>
         /// https://tc39.es/ecma262/#sec-resolvebinding
         /// </summary>
-        internal Reference ResolveBinding(string name, EnvironmentRecord env = null)
+        internal Reference ResolveBinding(string name, EnvironmentRecord? env = null)
         {
             env ??= ExecutionContext.LexicalEnvironment;
             return GetIdentifierReference(env, name, StrictModeScope.IsStrictModeCode);
         }
 
-        private static Reference GetIdentifierReference(EnvironmentRecord env, string name, bool strict)
+        private static Reference GetIdentifierReference(EnvironmentRecord? env, string name, bool strict)
         {
             if (env is null)
             {
@@ -757,11 +757,11 @@ namespace Jint
         /// <summary>
         /// https://tc39.es/ecma262/#sec-getnewtarget
         /// </summary>
-        internal JsValue GetNewTarget(EnvironmentRecord thisEnvironment = null)
+        internal JsValue GetNewTarget(EnvironmentRecord? thisEnvironment = null)
         {
             // we can take as argument if caller site has already determined the value, otherwise resolve
             thisEnvironment ??= ExecutionContext.GetThisEnvironment();
-            return thisEnvironment.NewTarget;
+            return thisEnvironment.NewTarget ?? JsValue.Undefined;
         }
 
         /// <summary>
@@ -796,7 +796,7 @@ namespace Jint
                 for (var i = functionDeclarations.Count - 1; i >= 0; i--)
                 {
                     var d = functionDeclarations[i];
-                    var fn = d.Id.Name;
+                    var fn = d.Id!.Name!;
                     if (!declaredFunctionNames.Contains(fn))
                     {
                         var fnDefinable = env.CanDeclareGlobalFunction(fn);
@@ -842,7 +842,7 @@ namespace Jint
                 }
             }
 
-            PrivateEnvironmentRecord privateEnv = null;
+            PrivateEnvironmentRecord? privateEnv = null;
             if (lexDeclarations != null)
             {
                 for (var i = 0; i < lexDeclarations.Count; i++)
@@ -874,7 +874,7 @@ namespace Jint
 
             foreach (var f in functionToInitialize)
             {
-                var fn = f.Name;
+                var fn = f.Name!;
 
                 if (env.HasLexicalDeclaration(fn))
                 {
@@ -895,7 +895,7 @@ namespace Jint
         /// <summary>
         /// https://tc39.es/ecma262/#sec-functiondeclarationinstantiation
         /// </summary>
-        internal ArgumentsInstance FunctionDeclarationInstantiation(
+        internal ArgumentsInstance? FunctionDeclarationInstantiation(
             FunctionInstance functionInstance,
             JsValue[] argumentsList)
         {
@@ -915,7 +915,7 @@ namespace Jint
             var arguments = canInitializeParametersOnDeclaration ? argumentsList : null;
             env.InitializeParameters(parameterNames, hasDuplicates, arguments);
 
-            ArgumentsInstance ao = null;
+            ArgumentsInstance? ao = null;
             if (configuration.ArgumentsObjectNeeded)
             {
                 if (strict || !simpleParameterList)
@@ -942,7 +942,7 @@ namespace Jint
             if (!canInitializeParametersOnDeclaration)
             {
                 // slower set
-                env.AddFunctionParameters(_activeEvaluationContext, func.Function, argumentsList);
+                env.AddFunctionParameters(_activeEvaluationContext!, func.Function, argumentsList);
             }
 
             // Let iteratorRecord be CreateListIteratorRecord(argumentsList).
@@ -955,9 +955,10 @@ namespace Jint
             if (!hasParameterExpressions)
             {
                 // NOTE: Only a single lexical environment is needed for the parameters and top-level vars.
-                for (var i = 0; i < configuration.VarsToInitialize.Count; i++)
+                var varsToInitialize = configuration.VarsToInitialize!;
+                for (var i = 0; i < varsToInitialize.Count; i++)
                 {
-                    var pair = configuration.VarsToInitialize[i];
+                    var pair = varsToInitialize[i];
                     env.CreateMutableBindingAndInitialize(pair.Name, canBeDeleted: false, JsValue.Undefined);
                 }
 
@@ -972,9 +973,10 @@ namespace Jint
 
                 UpdateVariableEnvironment(varEnv);
 
-                for (var i = 0; i < configuration.VarsToInitialize.Count; i++)
+                var varsToInitialize = configuration.VarsToInitialize!;
+                for (var i = 0; i < varsToInitialize.Count; i++)
                 {
-                    var pair = configuration.VarsToInitialize[i];
+                    var pair = varsToInitialize[i];
                     var initialValue = pair.InitialValue ?? env.GetBindingValue(pair.Name, strict: false);
                     varEnvRec.CreateMutableBindingAndInitialize(pair.Name, canBeDeleted: false, initialValue);
                 }
@@ -1024,7 +1026,7 @@ namespace Jint
                 var realm = Realm;
                 foreach (var f in configuration.FunctionsToInitialize)
                 {
-                    var fn = f.Name;
+                    var fn = f.Name!;
                     var fo = realm.Intrinsics.Function.InstantiateFunctionObject(f, lexEnv, privateEnv);
                     varEnv.SetMutableBinding(fn, fo, strict: false);
                 }
@@ -1055,7 +1057,7 @@ namespace Jint
             Script script,
             EnvironmentRecord varEnv,
             EnvironmentRecord lexEnv,
-            PrivateEnvironmentRecord privateEnv,
+            PrivateEnvironmentRecord? privateEnv,
             bool strict)
         {
             var hoistingScope = HoistingScope.GetProgramLevelDeclarations(script);
@@ -1074,7 +1076,7 @@ namespace Jint
                     {
                         var variablesDeclaration = nodes[i];
                         var identifier = (Identifier) variablesDeclaration.Declarations[0].Id;
-                        if (globalEnvironmentRecord.HasLexicalDeclaration(identifier.Name))
+                        if (globalEnvironmentRecord.HasLexicalDeclaration(identifier.Name!))
                         {
                             ExceptionHelper.ThrowSyntaxError(realm, "Identifier '" + identifier.Name + "' has already been declared");
                         }
@@ -1085,21 +1087,21 @@ namespace Jint
                 while (!ReferenceEquals(thisLex, varEnv))
                 {
                     var thisEnvRec = thisLex;
-                    if (!(thisEnvRec is ObjectEnvironmentRecord))
+                    if (thisEnvRec is not ObjectEnvironmentRecord)
                     {
                         ref readonly var nodes = ref hoistingScope._variablesDeclarations;
                         for (var i = 0; i < nodes.Count; i++)
                         {
                             var variablesDeclaration = nodes[i];
                             var identifier = (Identifier) variablesDeclaration.Declarations[0].Id;
-                            if (thisEnvRec.HasBinding(identifier.Name))
+                            if (thisEnvRec!.HasBinding(identifier.Name!))
                             {
                                 ExceptionHelper.ThrowSyntaxError(realm);
                             }
                         }
                     }
 
-                    thisLex = thisLex._outerEnv;
+                    thisLex = thisLex!._outerEnv;
                 }
             }
 
@@ -1112,7 +1114,7 @@ namespace Jint
                 for (var i = functionDeclarations.Count - 1; i >= 0; i--)
                 {
                     var d = functionDeclarations[i];
-                    var fn = d.Id.Name;
+                    var fn = d.Id!.Name!;
                     if (!declaredFunctionNames.Contains(fn))
                     {
                         if (varEnvRec is GlobalEnvironmentRecord ger)
@@ -1136,7 +1138,7 @@ namespace Jint
             var variableDeclarationsCount = variableDeclarations?.Count;
             for (var i = 0; i < variableDeclarationsCount; i++)
             {
-                var variableDeclaration = variableDeclarations[i];
+                var variableDeclaration = variableDeclarations![i];
                 boundNames.Clear();
                 variableDeclaration.GetBoundNames(boundNames);
                 for (var j = 0; j < boundNames.Count; j++)
@@ -1163,7 +1165,7 @@ namespace Jint
             for (var i = 0; i < lexicalDeclarationsCount; i++)
             {
                 boundNames.Clear();
-                var d = lexicalDeclarations[i];
+                var d = lexicalDeclarations![i];
                 d.GetBoundNames(boundNames);
                 for (var j = 0; j < boundNames.Count; j++)
                 {
@@ -1181,7 +1183,7 @@ namespace Jint
 
             foreach (var f in functionsToInitialize)
             {
-                var fn = f.Name;
+                var fn = f.Name!;
                 var fo = realm.Intrinsics.Function.InstantiateFunctionObject(f, lexEnv, privateEnv);
                 if (varEnvRec is GlobalEnvironmentRecord ger)
                 {
@@ -1233,7 +1235,7 @@ namespace Jint
         }
 
         [MethodImpl(MethodImplOptions.AggressiveInlining)]
-        internal void UpdatePrivateEnvironment(PrivateEnvironmentRecord newEnv)
+        internal void UpdatePrivateEnvironment(PrivateEnvironmentRecord? newEnv)
         {
             _executionContexts.ReplaceTopPrivateEnvironment(newEnv);
         }
@@ -1281,7 +1283,7 @@ namespace Jint
             return ExecuteWithConstraints(Options.Strict, Callback);
         }
 
-        internal JsValue Call(ICallable callable, JsValue thisObject, JsValue[] arguments, JintExpression expression)
+        internal JsValue Call(ICallable callable, JsValue thisObject, JsValue[] arguments, JintExpression? expression)
         {
             if (callable is FunctionInstance functionInstance)
             {
@@ -1328,7 +1330,7 @@ namespace Jint
             JsValue constructor,
             JsValue[] arguments,
             JsValue newTarget,
-            JintExpression expression)
+            JintExpression? expression)
         {
             if (constructor is FunctionInstance functionInstance)
             {
@@ -1342,7 +1344,7 @@ namespace Jint
             FunctionInstance functionInstance,
             JsValue thisObject,
             JsValue[] arguments,
-            JintExpression expression)
+            JintExpression? expression)
         {
             var callStackElement = new CallStackElement(functionInstance, expression, ExecutionContext);
             var recursionDepth = CallStack.Push(callStackElement);
@@ -1371,7 +1373,7 @@ namespace Jint
             FunctionInstance functionInstance,
             JsValue[] arguments,
             JsValue newTarget,
-            JintExpression expression)
+            JintExpression? expression)
         {
             var callStackElement = new CallStackElement(functionInstance, expression, ExecutionContext);
             var recursionDepth = CallStack.Push(callStackElement);

+ 2 - 4
Jint/EsprimaExtensions.cs

@@ -1,5 +1,3 @@
-#nullable enable
-
 using System.Runtime.CompilerServices;
 using Esprima;
 using Esprima.Ast;
@@ -81,7 +79,7 @@ namespace Jint
                 or Nodes.YieldExpression)
             {
                 var context = engine._activeEvaluationContext;
-                return JintExpression.Build(engine, expression).GetValue(context);
+                return JintExpression.Build(engine, expression).GetValue(context!);
             }
 
             return new Completion(CompletionType.Normal, JsValue.Undefined, expression.Location);
@@ -265,7 +263,7 @@ namespace Jint
             if (expression is Identifier identifier)
             {
                 var catchEnvRecord = (DeclarativeEnvironmentRecord) env;
-                catchEnvRecord.CreateMutableBindingAndInitialize(identifier.Name, canBeDeleted: false, value);
+                catchEnvRecord.CreateMutableBindingAndInitialize(identifier.Name!, canBeDeleted: false, value);
             }
             else if (expression is BindingPattern bindingPattern)
             {

+ 5 - 0
Jint/Extensions/JavascriptExtensions.cs

@@ -4,6 +4,11 @@ namespace Jint.Extensions
     {
         internal static string UpperToLowerCamelCase(this string str)
         {
+            if (char.IsLower(str[0]))
+            {
+                return str;
+            }
+
             var arr = str.ToCharArray();
             arr[0] = char.ToLowerInvariant(arr[0]);
             return new string(arr);

+ 9 - 8
Jint/Extensions/ReflectionExtensions.cs

@@ -1,3 +1,4 @@
+using System.Diagnostics.CodeAnalysis;
 using System.Reflection;
 using System.Runtime.CompilerServices;
 using Jint.Native;
@@ -9,7 +10,7 @@ namespace Jint.Extensions
     {
         private static readonly Type nullableType = typeof(Nullable<>);
 
-        internal static void SetValue(this MemberInfo memberInfo, object forObject, object value)
+        internal static void SetValue(this MemberInfo memberInfo, object forObject, object? value)
         {
             if (memberInfo.MemberType == MemberTypes.Field)
             {
@@ -35,7 +36,7 @@ namespace Jint.Extensions
             {
                 PropertyInfo propertyInfo => propertyInfo.PropertyType,
                 FieldInfo fieldInfo => fieldInfo.FieldType,
-                _ => null
+                _ => null!
             };
         }
 
@@ -125,18 +126,18 @@ namespace Jint.Extensions
         }
 
         public static bool TryConvertViaTypeCoercion(
-            Type _memberType,
+            Type memberType,
             ValueCoercionType valueCoercionType,
             JsValue value,
-            out object converted)
+            [NotNullWhen(true)] out object? converted)
         {
-            if (_memberType == typeof(bool) && (valueCoercionType & ValueCoercionType.Boolean) != 0)
+            if (memberType == typeof(bool) && (valueCoercionType & ValueCoercionType.Boolean) != 0)
             {
                 converted = TypeConverter.ToBoolean(value);
                 return true;
             }
 
-            if (_memberType == typeof(string)
+            if (memberType == typeof(string)
                 && !value.IsNullOrUndefined()
                 && (valueCoercionType & ValueCoercionType.String) != 0)
             {
@@ -146,12 +147,12 @@ namespace Jint.Extensions
                 return true;
             }
 
-            if (_memberType.IsClrNumericCoercible() && (valueCoercionType & ValueCoercionType.Number) != 0)
+            if (memberType.IsClrNumericCoercible() && (valueCoercionType & ValueCoercionType.Number) != 0)
             {
                 // we know how to print out correct string presentation for primitives
                 // that are non-null and non-undefined
                 var number = TypeConverter.ToNumber(value);
-                converted = number.AsNumberOfType(Type.GetTypeCode(_memberType));
+                converted = number.AsNumberOfType(Type.GetTypeCode(memberType));
                 return true;
             }
 

+ 27 - 27
Jint/HoistingScope.cs

@@ -5,20 +5,20 @@ namespace Jint
 {
     internal readonly struct HoistingScope
     {
-        internal readonly List<FunctionDeclaration> _functionDeclarations;
+        internal readonly List<FunctionDeclaration>? _functionDeclarations;
 
-        internal readonly List<VariableDeclaration> _variablesDeclarations;
-        internal readonly List<Key> _varNames;
+        internal readonly List<VariableDeclaration>? _variablesDeclarations;
+        internal readonly List<Key>? _varNames;
 
-        internal readonly List<Declaration> _lexicalDeclarations;
-        internal readonly List<string> _lexicalNames;
+        internal readonly List<Declaration>? _lexicalDeclarations;
+        internal readonly List<string>? _lexicalNames;
 
         private HoistingScope(
-            List<FunctionDeclaration> functionDeclarations,
-            List<Key> varNames,
-            List<VariableDeclaration> variableDeclarations,
-            List<Declaration> lexicalDeclarations,
-            List<string> lexicalNames)
+            List<FunctionDeclaration>? functionDeclarations,
+            List<Key>? varNames,
+            List<VariableDeclaration>? variableDeclarations,
+            List<Declaration>? lexicalDeclarations,
+            List<string>? lexicalNames)
         {
             _functionDeclarations = functionDeclarations;
             _varNames = varNames;
@@ -74,9 +74,9 @@ namespace Jint
                 treeWalker._lexicalNames);
         }
 
-        public static List<Declaration> GetLexicalDeclarations(BlockStatement statement)
+        public static List<Declaration>? GetLexicalDeclarations(BlockStatement statement)
         {
-            List<Declaration> lexicalDeclarations = null;
+            List<Declaration>? lexicalDeclarations = null;
             ref readonly var statementListItems = ref statement.Body;
             for (var i = 0; i < statementListItems.Count; i++)
             {
@@ -98,9 +98,9 @@ namespace Jint
             return lexicalDeclarations;
         }
 
-        public static List<Declaration> GetLexicalDeclarations(SwitchCase statement)
+        public static List<Declaration>? GetLexicalDeclarations(SwitchCase statement)
         {
-            List<Declaration> lexicalDeclarations = null;
+            List<Declaration>? lexicalDeclarations = null;
             ref readonly var statementListItems = ref statement.Consequent;
             for (var i = 0; i < statementListItems.Count; i++)
             {
@@ -126,7 +126,7 @@ namespace Jint
         public static void GetImportsAndExports(
             Module module,
             out HashSet<string> requestedModules,
-            out List<ImportEntry> importEntries,
+            out List<ImportEntry>? importEntries,
             out List<ExportEntry> localExportEntries,
             out List<ExportEntry> indirectExportEntries,
             out List<ExportEntry> starExportEntries)
@@ -203,16 +203,16 @@ namespace Jint
 
         private sealed class ScriptWalker
         {
-            internal List<FunctionDeclaration> _functions;
+            internal List<FunctionDeclaration>? _functions;
 
             private readonly bool _strict;
             private readonly bool _collectVarNames;
-            internal List<VariableDeclaration> _variableDeclarations;
-            internal List<Key> _varNames;
+            internal List<VariableDeclaration>? _variableDeclarations;
+            internal List<Key>? _varNames;
 
             private readonly bool _collectLexicalNames;
-            internal List<Declaration> _lexicalDeclarations;
-            internal List<string> _lexicalNames;
+            internal List<Declaration>? _lexicalDeclarations;
+            internal List<string>? _lexicalNames;
 
             public ScriptWalker(bool strict, bool collectVarNames, bool collectLexicalNames)
             {
@@ -221,7 +221,7 @@ namespace Jint
                 _collectLexicalNames = collectLexicalNames;
             }
 
-            public void Visit(Node node, Node parent)
+            public void Visit(Node node, Node? parent)
             {
                 foreach (var childNode in node.ChildNodes)
                 {
@@ -246,7 +246,7 @@ namespace Jint
                                 {
                                     if (declaration.Id is Identifier identifier)
                                     {
-                                        _varNames.Add(identifier.Name);
+                                        _varNames.Add(identifier.Name!);
                                     }
                                 }
                             }
@@ -264,7 +264,7 @@ namespace Jint
                                 {
                                     if (declaration.Id is Identifier identifier)
                                     {
-                                        _lexicalNames.Add(identifier.Name);
+                                        _lexicalNames.Add(identifier.Name!);
                                     }
                                 }
                             }
@@ -297,9 +297,9 @@ namespace Jint
 
         private sealed class ModuleWalker
         {
-            internal List<ImportEntry> _importEntries;
-            internal List<ExportEntry> _exportEntries;
-            internal HashSet<string> _requestedModules;
+            internal List<ImportEntry>? _importEntries;
+            internal List<ExportEntry>? _exportEntries;
+            internal HashSet<string>? _requestedModules;
 
             internal void Visit(Node node)
             {
@@ -314,7 +314,7 @@ namespace Jint
                     {
                         _importEntries ??= new();
                         _requestedModules ??= new();
-                        var import = childNode as ImportDeclaration;
+                        var import = (ImportDeclaration) childNode;
                         import.GetImportEntries(_importEntries, _requestedModules);
                     }
                     else if (childNode.Type == Nodes.ExportAllDeclaration ||

+ 1 - 1
Jint/IConstraint.cs

@@ -1,4 +1,4 @@
-namespace Jint
+namespace Jint
 {
     public interface IConstraint
     {

+ 1 - 0
Jint/Jint.csproj

@@ -7,6 +7,7 @@
     <LangVersion>latest</LangVersion>
     <IsPackable>true</IsPackable>
     <ImplicitUsings>enable</ImplicitUsings>
+    <Nullable>enable</Nullable>
   </PropertyGroup>
 
   <ItemGroup>

+ 10 - 10
Jint/JsValueExtensions.cs

@@ -1,4 +1,4 @@
-using System.Diagnostics.Contracts;
+using System.Diagnostics.Contracts;
 using System.Numerics;
 using System.Runtime.CompilerServices;
 using Esprima;
@@ -135,7 +135,7 @@ namespace Jint
                 ExceptionHelper.ThrowArgumentException("The value is not a date");
             }
 
-            return value as DateInstance;
+            return (DateInstance) value;
         }
 
         [Pure]
@@ -146,7 +146,7 @@ namespace Jint
                 ExceptionHelper.ThrowArgumentException("The value is not a regex");
             }
 
-            return value as RegExpInstance;
+            return (RegExpInstance) value;
         }
 
         [Pure]
@@ -158,7 +158,7 @@ namespace Jint
                 ExceptionHelper.ThrowArgumentException("The value is not an object");
             }
 
-            return value as ObjectInstance;
+            return (ObjectInstance) value;
         }
 
         [Pure]
@@ -170,7 +170,7 @@ namespace Jint
                 ExceptionHelper.ThrowArgumentException("The value is not an object");
             }
 
-            return value as TInstance;
+            return (value as TInstance)!;
         }
 
         [Pure]
@@ -182,7 +182,7 @@ namespace Jint
                 ExceptionHelper.ThrowArgumentException("The value is not an array");
             }
 
-            return value as ArrayInstance;
+            return (ArrayInstance) value;
         }
 
         [MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -385,14 +385,14 @@ namespace Jint
 
         [Pure]
         [MethodImpl(MethodImplOptions.AggressiveInlining)]
-        public static T TryCast<T>(this JsValue value) where T : class
+        public static T? TryCast<T>(this JsValue value) where T : class
         {
             return value as T;
         }
 
         [Pure]
         [MethodImpl(MethodImplOptions.AggressiveInlining)]
-        public static T TryCast<T>(this JsValue value, Action<JsValue> fail) where T : class
+        public static T? TryCast<T>(this JsValue value, Action<JsValue> fail) where T : class
         {
             if (value is T o)
             {
@@ -406,7 +406,7 @@ namespace Jint
 
         [Pure]
         [MethodImpl(MethodImplOptions.AggressiveInlining)]
-        public static T As<T>(this JsValue value) where T : ObjectInstance
+        public static T? As<T>(this JsValue value) where T : ObjectInstance
         {
             if (value.IsObject())
             {
@@ -423,7 +423,7 @@ namespace Jint
             if (value is not FunctionInstance instance)
             {
                 ThrowWrongTypeException(value, "FunctionInstance");
-                return null;
+                return null!;
             }
 
             return instance;

+ 0 - 2
Jint/ModuleBuilder.cs

@@ -1,5 +1,3 @@
-#nullable enable
-
 using Esprima;
 using Esprima.Ast;
 using Jint.Native;

+ 0 - 2
Jint/Native/AggregateError/AggregateErrorConstructor.cs

@@ -1,5 +1,3 @@
-#nullable enable
-
 using Jint.Native.Error;
 using Jint.Native.Function;
 using Jint.Native.Object;

+ 0 - 2
Jint/Native/AggregateError/AggregateErrorPrototype.cs

@@ -1,5 +1,3 @@
-#nullable enable
-
 using Jint.Collections;
 using Jint.Native.Object;
 using Jint.Runtime;

+ 8 - 8
Jint/Native/Argument/ArgumentsInstance.cs

@@ -1,4 +1,4 @@
-using System.Threading;
+using System.Threading;
 using Jint.Native.Function;
 using Jint.Native.Object;
 using Jint.Native.Symbol;
@@ -16,12 +16,12 @@ namespace Jint.Native.Argument
     public sealed class ArgumentsInstance : ObjectInstance
     {
         // cache property container for array iteration for less allocations
-        private static readonly ThreadLocal<HashSet<string>> _mappedNamed = new ThreadLocal<HashSet<string>>(() => new HashSet<string>());
+        private static readonly ThreadLocal<HashSet<string>> _mappedNamed = new(() => new HashSet<string>());
 
-        private FunctionInstance _func;
-        private Key[] _names;
-        private JsValue[] _args;
-        private DeclarativeEnvironmentRecord _env;
+        private FunctionInstance _func = null!;
+        private Key[] _names = null!;
+        private JsValue[] _args = null!;
+        private DeclarativeEnvironmentRecord _env = null!;
         private bool _canReturnToPool;
         private bool _hasRestParameter;
         private bool _materialized;
@@ -70,7 +70,7 @@ namespace Jint.Native.Argument
             }
             else
             {
-                ObjectInstance map = null;
+                ObjectInstance? map = null;
                 if (args.Length > 0)
                 {
                     var mappedNamed = _mappedNamed.Value;
@@ -102,7 +102,7 @@ namespace Jint.Native.Argument
             DefinePropertyOrThrow(GlobalSymbolRegistry.Iterator, new PropertyDescriptor(iteratorFunction, PropertyFlag.Writable | PropertyFlag.Configurable));
         }
 
-        public ObjectInstance ParameterMap { get; set; }
+        public ObjectInstance? ParameterMap { get; set; }
 
         internal override bool IsIntegerIndexedArray => true;
 

+ 7 - 7
Jint/Native/Array/ArrayConstructor.cs

@@ -1,4 +1,4 @@
-using System.Collections;
+using System.Collections;
 using Jint.Collections;
 using Jint.Native.Function;
 using Jint.Native.Iterator;
@@ -105,7 +105,7 @@ namespace Jint.Native.Array
         private ObjectInstance ConstructArrayFromArrayLike(
             JsValue thisObj,
             ObjectInstance objectInstance,
-            ICallable callable,
+            ICallable? callable,
             JsValue thisArg)
         {
             var source = ArrayOperations.For(objectInstance);
@@ -137,7 +137,7 @@ namespace Jint.Native.Array
                 source.TryGetValue(i, out var value);
                 if (!ReferenceEquals(callable, null))
                 {
-                    args[0] = value;
+                    args![0] = value;
                     args[1] = i;
                     jsValue = callable.Call(thisArg, args);
 
@@ -155,7 +155,7 @@ namespace Jint.Native.Array
 
             if (!ReferenceEquals(callable, null))
             {
-                _engine._jsValueArrayPool.ReturnArray(args);
+                _engine._jsValueArrayPool.ReturnArray(args!);
             }
 
             target.SetLength(length);
@@ -166,7 +166,7 @@ namespace Jint.Native.Array
         {
             private readonly JsValue _thisArg;
             private readonly ArrayOperations _instance;
-            private readonly ICallable _callable;
+            private readonly ICallable? _callable;
             private long _index = -1;
 
             public ArrayProtocol(
@@ -174,7 +174,7 @@ namespace Jint.Native.Array
                 JsValue thisArg,
                 ObjectInstance instance,
                 IteratorInstance iterator,
-                ICallable callable) : base(engine, iterator, 2)
+                ICallable? callable) : base(engine, iterator, 2)
             {
                 _thisArg = thisArg;
                 _instance = ArrayOperations.For(instance);
@@ -351,7 +351,7 @@ namespace Jint.Native.Array
         /// <summary>
         /// https://tc39.es/ecma262/#sec-arraycreate
         /// </summary>
-        internal ArrayInstance ArrayCreate(ulong length, ObjectInstance proto = null)
+        internal ArrayInstance ArrayCreate(ulong length, ObjectInstance? proto = null)
         {
             if (length > ArrayOperations.MaxArrayLength)
             {

+ 47 - 38
Jint/Native/Array/ArrayInstance.cs

@@ -1,4 +1,5 @@
-using System.Collections;
+using System.Collections;
+using System.Diagnostics.CodeAnalysis;
 using System.Runtime.CompilerServices;
 using Jint.Native.Object;
 using Jint.Native.Symbol;
@@ -9,13 +10,13 @@ namespace Jint.Native.Array
 {
     public class ArrayInstance : ObjectInstance, IEnumerable<JsValue>
     {
-        internal PropertyDescriptor _length;
+        internal PropertyDescriptor? _length;
 
         private const int MaxDenseArrayLength = 10_000_000;
 
         // we have dense and sparse, we usually can start with dense and fall back to sparse when necessary
-        internal PropertyDescriptor[] _dense;
-        private Dictionary<uint, PropertyDescriptor> _sparse;
+        internal PropertyDescriptor?[]? _dense;
+        private Dictionary<uint, PropertyDescriptor?>? _sparse;
 
         private ObjectChangeFlags _objectChangeFlags;
 
@@ -28,11 +29,11 @@ namespace Jint.Native.Array
 
             if (capacity < MaxDenseArrayLength)
             {
-                _dense = capacity > 0 ? new PropertyDescriptor[capacity] : System.Array.Empty<PropertyDescriptor>();
+                _dense = capacity > 0 ? new PropertyDescriptor?[capacity] : System.Array.Empty<PropertyDescriptor?>();
             }
             else
             {
-                _sparse = new Dictionary<uint, PropertyDescriptor>((int) (capacity <= 1024 ? capacity : 1024));
+                _sparse = new Dictionary<uint, PropertyDescriptor?>((int) (capacity <= 1024 ? capacity : 1024));
             }
         }
 
@@ -56,7 +57,7 @@ namespace Jint.Native.Array
             _length = new PropertyDescriptor(length, PropertyFlag.OnlyWritable);
         }
 
-        public ArrayInstance(Engine engine, Dictionary<uint, PropertyDescriptor> items) : base(engine)
+        public ArrayInstance(Engine engine, Dictionary<uint, PropertyDescriptor?> items) : base(engine)
         {
             _sparse = items;
             var length = items?.Count ?? 0;
@@ -132,7 +133,7 @@ namespace Jint.Native.Array
                 }
 
                 var oldLenDesc = _length;
-                var oldLen = (uint) TypeConverter.ToNumber(oldLenDesc.Value);
+                var oldLen = (uint) TypeConverter.ToNumber(oldLenDesc!.Value);
 
                 newLenDesc.Value = newLen;
                 if (newLen >= oldLen)
@@ -162,7 +163,7 @@ namespace Jint.Native.Array
                     return false;
                 }
 
-                var count = _dense?.Length ?? _sparse.Count;
+                var count = _dense?.Length ?? _sparse!.Count;
                 if (count < oldLen - newLen)
                 {
                     if (_dense != null)
@@ -196,7 +197,7 @@ namespace Jint.Native.Array
                     {
                         // in the case of sparse arrays, treat each concrete element instead of
                         // iterating over all indexes
-                        var keys = new List<uint>(_sparse.Keys);
+                        var keys = new List<uint>(_sparse!.Keys);
                         var keysCount = keys.Count;
                         for (var i = 0; i < keysCount; i++)
                         {
@@ -256,7 +257,7 @@ namespace Jint.Native.Array
         private bool DefineOwnProperty(uint index, PropertyDescriptor desc)
         {
             var oldLenDesc = _length;
-            var oldLen = (uint) TypeConverter.ToNumber(oldLenDesc.Value);
+            var oldLen = (uint) TypeConverter.ToNumber(oldLenDesc!.Value);
 
             if (index >= oldLen && !oldLenDesc.Writable)
             {
@@ -286,7 +287,7 @@ namespace Jint.Native.Array
                 return 0;
             }
 
-            return (uint) ((JsNumber) _length._value)._value;
+            return (uint) ((JsNumber) _length._value!)._value;
         }
 
         protected sealed override void AddProperty(JsValue property, PropertyDescriptor descriptor)
@@ -300,7 +301,7 @@ namespace Jint.Native.Array
             base.AddProperty(property, descriptor);
         }
 
-        protected sealed override bool TryGetProperty(JsValue property, out PropertyDescriptor descriptor)
+        protected sealed override bool TryGetProperty(JsValue property, [NotNullWhen(true)] out PropertyDescriptor? descriptor)
         {
             if (property == CommonProperties.Length)
             {
@@ -318,13 +319,14 @@ namespace Jint.Native.Array
                 return base.GetOwnPropertyKeys(types);
             }
 
-            var properties = new List<JsValue>(_dense?.Length ?? 0 + 1);
-            if (_dense != null)
+            var temp = _dense;
+            var properties = new List<JsValue>(temp?.Length ?? 0 + 1);
+            if (temp != null)
             {
-                var length = System.Math.Min(_dense.Length, GetLength());
+                var length = System.Math.Min(temp.Length, GetLength());
                 for (var i = 0; i < length; i++)
                 {
-                    if (_dense[i] != null)
+                    if (temp[i] != null)
                     {
                         properties.Add(JsString.Create(i));
                     }
@@ -332,7 +334,7 @@ namespace Jint.Native.Array
             }
             else
             {
-                foreach (var entry in _sparse)
+                foreach (var entry in _sparse!)
                 {
                     properties.Add(JsString.Create(entry.Key));
                 }
@@ -350,22 +352,28 @@ namespace Jint.Native.Array
 
         public sealed override IEnumerable<KeyValuePair<JsValue, PropertyDescriptor>> GetOwnProperties()
         {
-            if (_dense != null)
+            var temp = _dense;
+            if (temp != null)
             {
-                var length = System.Math.Min(_dense.Length, GetLength());
+                var length = System.Math.Min(temp.Length, GetLength());
                 for (var i = 0; i < length; i++)
                 {
-                    if (_dense[i] != null)
+                    var descriptor = temp[i];
+                    if (descriptor != null)
                     {
-                        yield return new KeyValuePair<JsValue, PropertyDescriptor>(TypeConverter.ToString(i), _dense[i]);
+                        yield return new KeyValuePair<JsValue, PropertyDescriptor>(TypeConverter.ToString(i), descriptor);
                     }
                 }
             }
             else
             {
-                foreach (var entry in _sparse)
+                foreach (var entry in _sparse!)
                 {
-                    yield return new KeyValuePair<JsValue, PropertyDescriptor>(TypeConverter.ToString(entry.Key), entry.Value);
+                    var descriptor = entry.Value;
+                    if (descriptor is not null)
+                    {
+                        yield return new KeyValuePair<JsValue, PropertyDescriptor>(TypeConverter.ToString(entry.Key), descriptor);
+                    }
                 }
             }
 
@@ -581,7 +589,7 @@ namespace Jint.Native.Array
         }
 
         [MethodImpl(MethodImplOptions.AggressiveInlining)]
-        internal void SetIndexValue(uint index, JsValue value, bool updateLength)
+        internal void SetIndexValue(uint index, JsValue? value, bool updateLength)
         {
             if (updateLength)
             {
@@ -603,7 +611,7 @@ namespace Jint.Native.Array
         [MethodImpl(MethodImplOptions.AggressiveInlining)]
         internal void SetLength(uint length)
         {
-            _length.Value = length;
+            _length!.Value = length;
         }
 
         internal uint GetSmallestIndex()
@@ -615,7 +623,7 @@ namespace Jint.Native.Array
 
             uint smallest = 0;
             // only try to help if collection reasonable small
-            if (_sparse.Count > 0 && _sparse.Count < 100 && !_sparse.ContainsKey(0))
+            if (_sparse!.Count > 0 && _sparse.Count < 100 && !_sparse.ContainsKey(0))
             {
                 smallest = uint.MaxValue;
                 foreach (var key in _sparse.Keys)
@@ -679,7 +687,7 @@ namespace Jint.Native.Array
             }
             else
             {
-                return _sparse.Remove(index);
+                return _sparse!.Remove(index);
             }
 
             return false;
@@ -687,7 +695,7 @@ namespace Jint.Native.Array
 
 
         [MethodImpl(MethodImplOptions.AggressiveInlining)]
-        private bool TryGetDescriptor(uint index, out PropertyDescriptor descriptor)
+        private bool TryGetDescriptor(uint index, [NotNullWhen(true)] out PropertyDescriptor? descriptor)
         {
             var temp = _dense;
             if (temp != null)
@@ -700,7 +708,7 @@ namespace Jint.Native.Array
                 return descriptor != null;
             }
 
-            return _sparse.TryGetValue(index, out descriptor);
+            return _sparse!.TryGetValue(index, out descriptor);
         }
 
         [MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -718,7 +726,7 @@ namespace Jint.Native.Array
 
             if (canUseDense)
             {
-                if (index >= (uint) _dense.Length)
+                if (index >= (uint) _dense!.Length)
                 {
                     EnsureCapacity((uint) newSize);
                 }
@@ -731,13 +739,13 @@ namespace Jint.Native.Array
                 {
                     ConvertToSparse();
                 }
-                _sparse[index] = desc;
+                _sparse![index] = desc;
             }
         }
 
         private void ConvertToSparse()
         {
-            _sparse = new Dictionary<uint, PropertyDescriptor>(_dense.Length <= 1024 ? _dense.Length : 0);
+            _sparse = new Dictionary<uint, PropertyDescriptor?>(_dense!.Length <= 1024 ? _dense.Length : 0);
             // need to move data
             for (uint i = 0; i < (uint) _dense.Length; ++i)
             {
@@ -797,7 +805,8 @@ namespace Jint.Native.Array
                 EnsureCapacity((uint) newLength);
             }
 
-            var canUseDirectIndexSet = _dense != null && newLength <= _dense.Length;
+            var temp = _dense;
+            var canUseDirectIndexSet = temp != null && newLength <= temp.Length;
 
             double n = initialLength;
             foreach (var argument in arguments)
@@ -805,7 +814,7 @@ namespace Jint.Native.Array
                 var desc = new PropertyDescriptor(argument, PropertyFlag.ConfigurableEnumerableWritable);
                 if (canUseDirectIndexSet)
                 {
-                    _dense[(uint) n] = desc;
+                    temp![(uint) n] = desc;
                 }
                 else
                 {
@@ -818,7 +827,7 @@ namespace Jint.Native.Array
             // check if we can set length fast without breaking ECMA specification
             if (n < uint.MaxValue && CanSetLength())
             {
-                _length.Value = (uint) n;
+                _length!.Value = (uint) n;
             }
             else
             {
@@ -833,7 +842,7 @@ namespace Jint.Native.Array
 
         private bool CanSetLength()
         {
-            if (!_length.IsAccessorDescriptor())
+            if (!_length!.IsAccessorDescriptor())
             {
                 return _length.Writable;
             }
@@ -1021,7 +1030,7 @@ namespace Jint.Native.Array
         public sealed override string ToString()
         {
             // debugger can make things hard when evaluates computed values
-            return "(" + (_length?._value.AsNumber() ?? 0) + ")[]";
+            return "(" + (_length?._value!.AsNumber() ?? 0) + ")[]";
         }
 
         private static void ThrowMaximumArraySizeReachedException(Engine engine, uint capacity)

+ 5 - 6
Jint/Native/Array/ArrayIteratorPrototype.cs

@@ -30,8 +30,8 @@ namespace Jint.Native.Array
         private sealed class ArrayLikeIterator : IteratorInstance
         {
             private readonly ArrayIteratorType _kind;
-            private readonly TypedArrayInstance _typedArray;
-            private readonly ArrayOperations _operations;
+            private readonly TypedArrayInstance? _typedArray;
+            private readonly ArrayOperations? _operations;
             private uint _position;
             private bool _closed;
 
@@ -57,12 +57,11 @@ namespace Jint.Native.Array
                 }
                 else
                 {
-                    len = _operations.GetLength();
+                    len = _operations!.GetLength();
                 }
 
                 if (!_closed && _position < len)
                 {
-                    JsValue value;
                     if (_typedArray is not null)
                     {
                         nextItem = _kind switch
@@ -74,7 +73,7 @@ namespace Jint.Native.Array
                     }
                     else
                     {
-                        _operations.TryGetValue(_position, out value);
+                        _operations!.TryGetValue(_position, out var value);
                         if (_kind == ArrayIteratorType.Key)
                         {
                             nextItem = new ValueIteratorPosition(_engine, _position);
@@ -99,4 +98,4 @@ namespace Jint.Native.Array
             }
         }
     }
-}
+}

+ 5 - 5
Jint/Native/Array/ArrayOperations.cs

@@ -102,16 +102,16 @@ namespace Jint.Native.Array
                 {
                     if (!_initialized)
                     {
-                        return null;
+                        return JsValue.Undefined;
                     }
                     else
                     {
-                        return _obj.TryGetValue(_current, out var temp) ? temp : null;
+                        return _obj.TryGetValue(_current, out var temp) ? temp : JsValue.Undefined;
                     }
                 }
             }
 
-            object IEnumerator.Current => Current;
+            object? IEnumerator.Current => Current;
 
             public void Dispose()
             {
@@ -216,10 +216,10 @@ namespace Jint.Native.Array
                 => _target.GetSmallestIndex();
 
             public override uint GetLength()
-                => (uint) ((JsNumber) _target._length._value)._value;
+                => (uint) ((JsNumber) _target._length!._value!)._value;
 
             public override ulong GetLongLength()
-                => (ulong) ((JsNumber) _target._length._value)._value;
+                => (ulong) ((JsNumber) _target._length!._value!)._value;
 
             public override void SetLength(ulong length)
                 => _target.Set(CommonProperties.Length, length, true);

+ 22 - 22
Jint/Native/Array/ArrayPrototype.cs

@@ -1,4 +1,4 @@
-using Jint.Collections;
+using Jint.Collections;
 using Jint.Native.Iterator;
 using Jint.Native.Number;
 using Jint.Native.Object;
@@ -18,7 +18,7 @@ namespace Jint.Native.Array
     {
         private readonly Realm _realm;
         private readonly ArrayConstructor _constructor;
-        internal ClrFunctionInstance _originalIteratorFunction;
+        internal ClrFunctionInstance? _originalIteratorFunction;
 
         internal ArrayPrototype(
             Engine engine,
@@ -81,7 +81,7 @@ namespace Jint.Native.Array
                 [GlobalSymbolRegistry.Iterator] = new PropertyDescriptor(_originalIteratorFunction, propertyFlags),
                 [GlobalSymbolRegistry.Unscopables] = new LazyPropertyDescriptor(_engine, static state =>
                 {
-                    var unscopables = new ObjectInstance((Engine) state)
+                    var unscopables = new ObjectInstance((Engine) state!)
                     {
                         _prototype = null
                     };
@@ -526,8 +526,8 @@ namespace Jint.Native.Array
             uint sourceLen,
             long start,
             double depth,
-            ICallable mapperFunction = null,
-            JsValue thisArg = null)
+            ICallable? mapperFunction = null,
+            JsValue? thisArg = null)
         {
             var targetIndex = start;
             var sourceIndex = 0;
@@ -550,7 +550,7 @@ namespace Jint.Native.Array
                     {
                         callArguments[0] = element;
                         callArguments[1] = JsNumber.Create(sourceIndex);
-                        element = mapperFunction.Call(thisArg, callArguments);
+                        element = mapperFunction.Call(thisArg ?? Undefined, callArguments);
                     }
 
                     var shouldFlatten = false;
@@ -1004,7 +1004,7 @@ namespace Jint.Native.Array
             var obj = ArrayOperations.For(objectInstance);
 
             var compareArg = arguments.At(0);
-            ICallable compareFn = null;
+            ICallable? compareFn = null;
             if (!compareArg.IsUndefined())
             {
                 if (compareArg is not ICallable callable)
@@ -1036,7 +1036,7 @@ namespace Jint.Native.Array
             // don't eat inner exceptions
             try
             {
-                var array = items.OrderBy(x => x, ArrayComparer.WithFunction(_engine, compareFn)).ToArray();
+                var array = items.OrderBy(x => x, ArrayComparer.WithFunction(_engine, compareFn!)).ToArray();
 
                 uint j;
                 for (j = 0; j < itemCount; ++j)
@@ -1176,20 +1176,20 @@ namespace Jint.Native.Array
 
                 if (lowerExists && upperExists)
                 {
-                    o.Set(lower, upperValue, throwOnError: true);
-                    o.Set(upper, lowerValue, throwOnError: true);
+                    o.Set(lower, upperValue!, throwOnError: true);
+                    o.Set(upper, lowerValue!, throwOnError: true);
                 }
 
                 if (!lowerExists && upperExists)
                 {
-                    o.Set(lower, upperValue, throwOnError: true);
+                    o.Set(lower, upperValue!, throwOnError: true);
                     o.DeletePropertyOrThrow(upper);
                 }
 
                 if (lowerExists && !upperExists)
                 {
                     o.DeletePropertyOrThrow(lower);
-                    o.Set(upper, lowerValue, throwOnError: true);
+                    o.Set(upper, lowerValue!, throwOnError: true);
                 }
 
                 lower++;
@@ -1479,11 +1479,11 @@ namespace Jint.Native.Array
                 return new ArrayComparer(engine, compare);
             }
 
-            private readonly Engine _engine;
-            private readonly ICallable _compare;
+            private readonly Engine? _engine;
+            private readonly ICallable? _compare;
             private readonly JsValue[] _comparableArray = new JsValue[2];
 
-            private ArrayComparer(Engine engine, ICallable compare)
+            private ArrayComparer(Engine? engine, ICallable? compare)
             {
                 _engine = engine;
                 _compare = compare;
@@ -1511,8 +1511,8 @@ namespace Jint.Native.Array
                     }
                 }
 
-                var xUndefined = x.IsUndefined();
-                var yUndefined = y.IsUndefined();
+                var xUndefined = x!.IsUndefined();
+                var yUndefined = y!.IsUndefined();
                 if (xUndefined && yUndefined)
                 {
                     return 0;
@@ -1530,10 +1530,10 @@ namespace Jint.Native.Array
 
                 if (_compare != null)
                 {
-                    _engine.RunBeforeExecuteStatementChecks(null);
+                    _engine!.RunBeforeExecuteStatementChecks(null);
 
-                    _comparableArray[0] = x;
-                    _comparableArray[1] = y;
+                    _comparableArray[0] = x!;
+                    _comparableArray[1] = y!;
 
                     var s = TypeConverter.ToNumber(_compare.Call(Undefined, _comparableArray));
                     if (s < 0)
@@ -1549,8 +1549,8 @@ namespace Jint.Native.Array
                     return 0;
                 }
 
-                var xString = TypeConverter.ToString(x);
-                var yString = TypeConverter.ToString(y);
+                var xString = TypeConverter.ToString(x!);
+                var yString = TypeConverter.ToString(y!);
 
                 return string.CompareOrdinal(xString, yString);
             }

+ 1 - 1
Jint/Native/ArrayBuffer/ArrayBufferConstructor.cs

@@ -87,7 +87,7 @@ namespace Jint.Native.ArrayBuffer
             var obj = OrdinaryCreateFromConstructor(
                 constructor,
                 static intrinsics => intrinsics.ArrayBuffer.PrototypeObject,
-                static (engine, realm, state) => new ArrayBufferInstance(engine, (ulong) ((JsNumber) state)._value),
+                static (engine, realm, state) => new ArrayBufferInstance(engine, (ulong) ((JsNumber) state!)._value),
                 JsNumber.Create(byteLength));
 
             return obj;

+ 5 - 5
Jint/Native/ArrayBuffer/ArrayBufferInstance.cs

@@ -12,7 +12,7 @@ namespace Jint.Native.ArrayBuffer
         // so that we don't need to allocate while or reading setting values
         private readonly byte[] _workBuffer = new byte[8];
 
-        private byte[] _arrayBufferData;
+        private byte[]? _arrayBufferData;
         private readonly JsValue _arrayBufferDetachKey = Undefined;
 
         internal ArrayBufferInstance(
@@ -33,8 +33,8 @@ namespace Jint.Native.ArrayBuffer
             return new byte[byteLength];
         }
 
-        internal int ArrayBufferByteLength => _arrayBufferData.Length;
-        internal byte[] ArrayBufferData => _arrayBufferData;
+        internal int ArrayBufferByteLength => _arrayBufferData?.Length ?? 0;
+        internal byte[]? ArrayBufferData => _arrayBufferData;
 
         internal bool IsDetachedBuffer => _arrayBufferData is null;
         internal bool IsSharedArrayBuffer => false; // TODO SharedArrayBuffer
@@ -42,7 +42,7 @@ namespace Jint.Native.ArrayBuffer
         /// <summary>
         /// https://tc39.es/ecma262/#sec-detacharraybuffer
         /// </summary>
-        internal void DetachArrayBuffer(JsValue key = null)
+        internal void DetachArrayBuffer(JsValue? key = null)
         {
             key ??= Undefined;
 
@@ -111,7 +111,7 @@ namespace Jint.Native.ArrayBuffer
         internal TypedArrayValue RawBytesToNumeric(TypedArrayElementType type, int byteIndex, bool isLittleEndian)
         {
             var elementSize = type.GetElementSize();
-            var rawBytes = _arrayBufferData;
+            var rawBytes = _arrayBufferData!;
 
             // 8 byte values require a little more at the moment
             var needsReverse = !isLittleEndian

+ 1 - 1
Jint/Native/ArrayBuffer/ArrayBufferOrder.cs

@@ -6,4 +6,4 @@ namespace Jint.Native.ArrayBuffer
         SecCst,
         Unordered
     }
-}
+}

+ 1 - 1
Jint/Native/ArrayBuffer/ArrayBufferPrototype.cs

@@ -155,4 +155,4 @@ namespace Jint.Native.ArrayBuffer
             return bufferInstance;
         }
     }
-}
+}

+ 5 - 6
Jint/Native/BigInt/BigIntConstructor.cs

@@ -1,4 +1,4 @@
-using System.Numerics;
+using System.Numerics;
 using Jint.Collections;
 using Jint.Native.Function;
 using Jint.Native.Object;
@@ -115,9 +115,9 @@ public sealed class BigIntConstructor : FunctionInstance, IConstructor
         var o = OrdinaryCreateFromConstructor(
             newTarget,
             static intrinsics => intrinsics.BigInt.PrototypeObject,
-            static (engine, realm, state) => new BigIntInstance(engine, state),
+            static (engine, realm, state) => new BigIntInstance(engine, state!),
             value);
-        
+
         return o;
     }
 
@@ -125,10 +125,9 @@ public sealed class BigIntConstructor : FunctionInstance, IConstructor
 
     public BigIntInstance Construct(JsBigInt value)
     {
-        var instance = new BigIntInstance(Engine)
+        var instance = new BigIntInstance(Engine, value)
         {
-            _prototype = PrototypeObject,
-            BigIntData = value
+            _prototype = PrototypeObject
         };
 
         return instance;

+ 4 - 9
Jint/Native/BigInt/BigIntInstance.cs

@@ -1,17 +1,12 @@
-using Jint.Native.Object;
+using Jint.Native.Object;
 using Jint.Runtime;
 
 namespace Jint.Native.BigInt;
 
 public sealed class BigIntInstance : ObjectInstance, IPrimitiveInstance
 {
-    public BigIntInstance(Engine engine)
-        : base(engine, ObjectClass.Object)
-    {
-    }
-
     public BigIntInstance(Engine engine, JsBigInt value)
-        : this(engine)
+        : base(engine, ObjectClass.Object)
     {
         BigIntData = value;
     }
@@ -20,5 +15,5 @@ public sealed class BigIntInstance : ObjectInstance, IPrimitiveInstance
 
     JsValue IPrimitiveInstance.PrimitiveValue => BigIntData;
 
-    public JsBigInt BigIntData { get; internal init; }
-}
+    public JsBigInt BigIntData { get; }
+}

+ 1 - 1
Jint/Native/BigInt/BigIntPrototype.cs

@@ -1,4 +1,4 @@
-using System.Numerics;
+using System.Numerics;
 using Jint.Collections;
 using Jint.Native.Object;
 using Jint.Native.Symbol;

+ 4 - 5
Jint/Native/Boolean/BooleanConstructor.cs

@@ -1,4 +1,4 @@
-using Jint.Native.Function;
+using Jint.Native.Function;
 using Jint.Native.Object;
 using Jint.Runtime;
 using Jint.Runtime.Descriptors;
@@ -51,16 +51,15 @@ namespace Jint.Native.Boolean
             var o = OrdinaryCreateFromConstructor(
                 newTarget,
                 static intrinsics => intrinsics.Boolean.PrototypeObject,
-                static (engine, realm, state) => new BooleanInstance(engine, (JsBoolean) state), b);
+                static (engine, realm, state) => new BooleanInstance(engine, (JsBoolean) state!), b);
             return o;
         }
 
         public BooleanInstance Construct(JsBoolean value)
         {
-            var instance = new BooleanInstance(Engine)
+            var instance = new BooleanInstance(Engine, value)
             {
-                _prototype = PrototypeObject,
-                BooleanData = value,
+                _prototype = PrototypeObject
             };
 
             return instance;

+ 3 - 8
Jint/Native/Boolean/BooleanInstance.cs

@@ -1,15 +1,10 @@
-using Jint.Native.Object;
+using Jint.Native.Object;
 using Jint.Runtime;
 
 namespace Jint.Native.Boolean
 {
     public class BooleanInstance : ObjectInstance, IPrimitiveInstance
     {
-        public BooleanInstance(Engine engine)
-            : base(engine, ObjectClass.Boolean)
-        {
-        }
-
         public BooleanInstance(Engine engine, JsBoolean value)
             : base(engine, ObjectClass.Boolean)
         {
@@ -20,6 +15,6 @@ namespace Jint.Native.Boolean
 
         JsValue IPrimitiveInstance.PrimitiveValue => BooleanData;
 
-        public JsValue BooleanData { get; internal init; }
+        public JsValue BooleanData { get; }
     }
-}
+}

+ 3 - 4
Jint/Native/Boolean/BooleanPrototype.cs

@@ -1,4 +1,4 @@
-using Jint.Collections;
+using Jint.Collections;
 using Jint.Native.Object;
 using Jint.Runtime;
 using Jint.Runtime.Descriptors;
@@ -18,10 +18,9 @@ namespace Jint.Native.Boolean
             Engine engine,
             Realm realm,
             BooleanConstructor constructor,
-            ObjectPrototype objectPrototype) : base(engine)
+            ObjectPrototype objectPrototype) : base(engine, JsBoolean.False)
         {
             _prototype = objectPrototype;
-            BooleanData = JsBoolean.False;
             _realm = realm;
             _constructor = constructor;
         }
@@ -59,4 +58,4 @@ namespace Jint.Native.Boolean
             return ((JsBoolean) b)._value ? JsString.TrueString : JsString.FalseString;
         }
     }
-}
+}

+ 1 - 1
Jint/Native/DataView/DataViewConstructor.cs

@@ -80,7 +80,7 @@ namespace Jint.Native.DataView
             var o = OrdinaryCreateFromConstructor(
                 newTarget,
                 static intrinsics => intrinsics.DataView.PrototypeObject,
-                static (Engine engine, Realm _, object _) => new DataViewInstance(engine));
+                static (Engine engine, Realm _, object? _) => new DataViewInstance(engine));
 
             if (buffer.IsDetachedBuffer)
             {

+ 2 - 2
Jint/Native/DataView/DataViewInstance.cs

@@ -8,7 +8,7 @@ namespace Jint.Native.DataView
     /// </summary>
     public sealed class DataViewInstance : ObjectInstance
     {
-        internal ArrayBufferInstance _viewedArrayBuffer;
+        internal ArrayBufferInstance? _viewedArrayBuffer;
         internal uint _byteLength;
         internal uint _byteOffset;
 
@@ -16,4 +16,4 @@ namespace Jint.Native.DataView
         {
         }
     }
-}
+}

+ 6 - 6
Jint/Native/DataView/DataViewPrototype.cs

@@ -79,7 +79,7 @@ namespace Jint.Native.DataView
                 ExceptionHelper.ThrowTypeError(_realm, "Method get DataView.prototype.buffer called on incompatible receiver " + thisObj);
             }
 
-            return o._viewedArrayBuffer;
+            return o._viewedArrayBuffer!;
         }
 
         /// <summary>
@@ -93,7 +93,7 @@ namespace Jint.Native.DataView
                 ExceptionHelper.ThrowTypeError(_realm, "Method get DataView.prototype.byteLength called on incompatible receiver " + thisObj);
             }
 
-            var buffer = o._viewedArrayBuffer;
+            var buffer = o._viewedArrayBuffer!;
             buffer.AssertNotDetached();
 
             return JsNumber.Create(o._byteLength);
@@ -110,7 +110,7 @@ namespace Jint.Native.DataView
                 ExceptionHelper.ThrowTypeError(_realm, "Method get DataView.prototype.byteOffset called on incompatible receiver " + thisObj);
             }
 
-            var buffer = o._viewedArrayBuffer;
+            var buffer = o._viewedArrayBuffer!;
             buffer.AssertNotDetached();
 
             return JsNumber.Create(o._byteOffset);
@@ -233,7 +233,7 @@ namespace Jint.Native.DataView
 
             var getIndex = (int) TypeConverter.ToIndex(_realm, requestIndex);
             var isLittleEndianBoolean = TypeConverter.ToBoolean(isLittleEndian);
-            var buffer = dataView._viewedArrayBuffer;
+            var buffer = dataView._viewedArrayBuffer!;
 
             buffer.AssertNotDetached();
 
@@ -278,7 +278,7 @@ namespace Jint.Native.DataView
             }
 
             var isLittleEndianBoolean = TypeConverter.ToBoolean(isLittleEndian);
-            var buffer = dataView._viewedArrayBuffer;
+            var buffer = dataView._viewedArrayBuffer!;
             buffer.AssertNotDetached();
 
             var viewOffset = dataView._byteOffset;
@@ -294,4 +294,4 @@ namespace Jint.Native.DataView
             return Undefined;
         }
     }
-}
+}

+ 2 - 2
Jint/Native/Date/DateConstructor.cs

@@ -1,4 +1,4 @@
-using System.Globalization;
+using System.Globalization;
 using Jint.Collections;
 using Jint.Native.Function;
 using Jint.Native.Object;
@@ -211,7 +211,7 @@ namespace Jint.Native.Date
             var o = OrdinaryCreateFromConstructor(
                 newTarget,
                 static intrinsics => intrinsics.Date.PrototypeObject,
-                static (Engine engine, Realm _, object _) => new DateInstance(engine));
+                static (Engine engine, Realm _, object? _) => new DateInstance(engine));
             o.DateValue = dv;
             return o;
         }

+ 1 - 1
Jint/Native/Date/DateInstance.cs

@@ -1,4 +1,4 @@
-using System.Globalization;
+using System.Globalization;
 using Jint.Native.Object;
 using Jint.Runtime;
 

+ 1 - 1
Jint/Native/Date/DatePrototype.cs

@@ -1,4 +1,4 @@
-using System.Globalization;
+using System.Globalization;
 using System.Runtime.CompilerServices;
 using Jint.Collections;
 using Jint.Native.Object;

+ 2 - 2
Jint/Native/Error/ErrorConstructor.cs

@@ -1,4 +1,4 @@
-using Jint.Native.Function;
+using Jint.Native.Function;
 using Jint.Native.Object;
 using Jint.Runtime;
 using Jint.Runtime.Descriptors;
@@ -46,7 +46,7 @@ namespace Jint.Native.Error
             var o = OrdinaryCreateFromConstructor(
                 newTarget,
                 _intrinsicDefaultProto,
-                static (Engine engine, Realm _, object _) => new ErrorInstance(engine));
+                static (Engine engine, Realm _, object? _) => new ErrorInstance(engine));
 
             var jsValue = arguments.At(0);
             if (!jsValue.IsUndefined())

+ 0 - 2
Jint/Native/Error/ErrorInstance.cs

@@ -1,5 +1,3 @@
-#nullable enable
-
 using Jint.Native.Object;
 using Jint.Runtime;
 

+ 1 - 1
Jint/Native/Error/ErrorPrototype.cs

@@ -1,4 +1,4 @@
-using Jint.Collections;
+using Jint.Collections;
 using Jint.Native.Object;
 using Jint.Runtime;
 using Jint.Runtime.Descriptors;

+ 2 - 2
Jint/Native/Function/BindFunctionInstance.cs

@@ -1,4 +1,4 @@
-using Jint.Native.Object;
+using Jint.Native.Object;
 using Jint.Runtime;
 
 namespace Jint.Native.Function
@@ -12,7 +12,7 @@ namespace Jint.Native.Function
 
         public BindFunctionInstance(Engine engine,
             Realm realm,
-            ObjectInstance proto,
+            ObjectInstance? proto,
             ObjectInstance targetFunction,
             JsValue boundThis,
             JsValue[] boundArgs)

+ 0 - 2
Jint/Native/Function/ClassDefinition.cs

@@ -1,5 +1,3 @@
-#nullable enable
-
 using Esprima;
 using Esprima.Ast;
 using Jint.Native.Object;

+ 1 - 1
Jint/Native/Function/ConstructorKind.cs

@@ -5,4 +5,4 @@ namespace Jint.Native.Function
         Base,
         Derived
     }
-}
+}

+ 5 - 5
Jint/Native/Function/EvalFunctionInstance.cs

@@ -1,4 +1,4 @@
-using Esprima;
+using Esprima;
 using Esprima.Ast;
 using Jint.Runtime;
 using Jint.Runtime.Descriptors;
@@ -67,7 +67,7 @@ namespace Jint.Native.Function
             }
 
             var parser = new JavaScriptParser(x.ToString(), ParserOptions);
-            Script script = null;
+            Script? script = null;
             try
             {
                 script = parser.ParseScript(strictCaller);
@@ -76,7 +76,7 @@ namespace Jint.Native.Function
             {
                 if (e.Description == Messages.InvalidLHSInAssignment)
                 {
-                    ExceptionHelper.ThrowReferenceError(callerRealm, (string) null);
+                    ExceptionHelper.ThrowReferenceError(callerRealm, (string?) null);
                 }
                 else
                 {
@@ -110,7 +110,7 @@ namespace Jint.Native.Function
             {
                 EnvironmentRecord lexEnv;
                 EnvironmentRecord varEnv;
-                PrivateEnvironmentRecord privateEnv;
+                PrivateEnvironmentRecord? privateEnv;
                 if (direct)
                 {
                     lexEnv = JintEnvironment.NewDeclarativeEnvironment(_engine, ctx.LexicalEnvironment);
@@ -138,7 +138,7 @@ namespace Jint.Native.Function
                     Engine.EvalDeclarationInstantiation(script, varEnv, lexEnv, privateEnv, strictEval);
 
                     var statement = new JintScript(script);
-                    var result = statement.Execute(_engine._activeEvaluationContext);
+                    var result = statement.Execute(_engine._activeEvaluationContext!);
                     var value = result.GetValueOrDefault();
 
                     if (result.Type == CompletionType.Throw)

+ 9 - 9
Jint/Native/Function/FunctionConstructor.cs

@@ -1,4 +1,4 @@
-using Esprima;
+using Esprima;
 using Esprima.Ast;
 using Jint.Native.Object;
 using Jint.Runtime;
@@ -70,7 +70,7 @@ namespace Jint.Native.Function
                 newTarget = constructor;
             }
 
-            Func<Intrinsics, ObjectInstance> fallbackProto = null;
+            Func<Intrinsics, ObjectInstance>? fallbackProto = null;
             switch (kind)
             {
                 case FunctionKind.Normal:
@@ -105,10 +105,10 @@ namespace Jint.Native.Function
                 body = TypeConverter.ToString(args[argCount - 1]);
             }
 
-            IFunction function = null;
+            IFunction? function = null;
             try
             {
-                string functionExpression = null;
+                string? functionExpression = null;
                 if (argCount == 0)
                 {
                     switch (kind)
@@ -185,7 +185,7 @@ namespace Jint.Native.Function
             var proto = GetPrototypeFromConstructor(newTarget, fallbackProto);
             var realmF = _realm;
             var scope = realmF.GlobalEnv;
-            PrivateEnvironmentRecord privateScope = null;
+            PrivateEnvironmentRecord? privateScope = null;
 
             var definition = new JintFunctionDefinition(_engine, function);
             FunctionInstance F = OrdinaryFunctionCreate(proto, definition, function.Strict ? FunctionThisMode.Strict : FunctionThisMode.Global, scope, privateScope);
@@ -218,7 +218,7 @@ namespace Jint.Native.Function
             JintFunctionDefinition function,
             FunctionThisMode thisMode,
             EnvironmentRecord scope,
-            PrivateEnvironmentRecord privateScope)
+            PrivateEnvironmentRecord? privateScope)
         {
             return new ScriptFunctionInstance(
                 _engine,
@@ -238,7 +238,7 @@ namespace Jint.Native.Function
         internal FunctionInstance InstantiateFunctionObject(
             JintFunctionDefinition functionDeclaration,
             EnvironmentRecord scope,
-            PrivateEnvironmentRecord privateScope)
+            PrivateEnvironmentRecord? privateScope)
         {
             return !functionDeclaration.Function.Generator
                 ? InstantiateOrdinaryFunctionObject(functionDeclaration, scope, privateScope)
@@ -251,7 +251,7 @@ namespace Jint.Native.Function
         private FunctionInstance InstantiateOrdinaryFunctionObject(
             JintFunctionDefinition functionDeclaration,
             EnvironmentRecord scope,
-            PrivateEnvironmentRecord privateScope)
+            PrivateEnvironmentRecord? privateScope)
         {
             var F = OrdinaryFunctionCreate(
                 _realm.Intrinsics.Function.PrototypeObject,
@@ -272,7 +272,7 @@ namespace Jint.Native.Function
         private FunctionInstance InstantiateGeneratorFunctionObject(
             JintFunctionDefinition functionDeclaration,
             EnvironmentRecord scope,
-            PrivateEnvironmentRecord privateScope)
+            PrivateEnvironmentRecord? privateScope)
         {
             // TODO generators
             return InstantiateOrdinaryFunctionObject(functionDeclaration, scope, privateScope);

+ 17 - 18
Jint/Native/Function/FunctionInstance.cs

@@ -1,4 +1,4 @@
-using System.Runtime.CompilerServices;
+using System.Runtime.CompilerServices;
 using Esprima.Ast;
 using Jint.Native.Object;
 using Jint.Native.Proxy;
@@ -11,25 +11,25 @@ namespace Jint.Native.Function
 {
     public abstract class FunctionInstance : ObjectInstance, ICallable
     {
-        protected PropertyDescriptor _prototypeDescriptor;
+        protected PropertyDescriptor? _prototypeDescriptor;
 
-        protected internal PropertyDescriptor _length;
-        internal PropertyDescriptor _nameDescriptor;
+        protected internal PropertyDescriptor? _length;
+        internal PropertyDescriptor? _nameDescriptor;
 
-        protected internal EnvironmentRecord _environment;
-        internal readonly JintFunctionDefinition _functionDefinition;
+        protected internal EnvironmentRecord? _environment;
+        internal readonly JintFunctionDefinition _functionDefinition = null!;
         internal readonly FunctionThisMode _thisMode;
         internal JsValue _homeObject = Undefined;
         internal ConstructorKind _constructorKind = ConstructorKind.Base;
 
         internal Realm _realm;
-        internal PrivateEnvironmentRecord _privateEnvironment;
-        private readonly IScriptOrModule _scriptOrModule;
+        internal PrivateEnvironmentRecord? _privateEnvironment;
+        private readonly IScriptOrModule? _scriptOrModule;
 
         protected FunctionInstance(
             Engine engine,
             Realm realm,
-            JsString name)
+            JsString? name)
             : this(engine, realm, name, FunctionThisMode.Global, ObjectClass.Function)
         {
         }
@@ -43,7 +43,7 @@ namespace Jint.Native.Function
             : this(
                 engine,
                 realm,
-                !string.IsNullOrWhiteSpace(function.Name) ? new JsString(function.Name) : null,
+                !string.IsNullOrWhiteSpace(function.Name) ? new JsString(function.Name!) : null,
                 thisMode)
         {
             _functionDefinition = function;
@@ -53,7 +53,7 @@ namespace Jint.Native.Function
         internal FunctionInstance(
             Engine engine,
             Realm realm,
-            JsString name,
+            JsString? name,
             FunctionThisMode thisMode = FunctionThisMode.Global,
             ObjectClass objectClass = ObjectClass.Function)
             : base(engine, objectClass)
@@ -181,7 +181,7 @@ namespace Jint.Native.Function
         /// <summary>
         /// https://tc39.es/ecma262/#sec-setfunctionname
         /// </summary>
-        internal void SetFunctionName(JsValue name, string prefix = null, bool force = false)
+        internal void SetFunctionName(JsValue name, string? prefix = null, bool force = false)
         {
             if (!force && _nameDescriptor != null && UnwrapJsValue(_nameDescriptor) != JsString.Empty)
             {
@@ -213,8 +213,8 @@ namespace Jint.Native.Function
         internal T OrdinaryCreateFromConstructor<T, TState>(
             JsValue constructor,
             Func<Intrinsics, ObjectInstance> intrinsicDefaultProto,
-            Func<Engine, Realm, TState, T> objectCreator,
-            TState state = default) where T : ObjectInstance
+            Func<Engine, Realm, TState?, T> objectCreator,
+            TState? state = default) where T : ObjectInstance
         {
             var proto = GetPrototypeFromConstructor(constructor, intrinsicDefaultProto);
 
@@ -229,8 +229,7 @@ namespace Jint.Native.Function
         [MethodImpl(MethodImplOptions.AggressiveInlining)]
         internal ObjectInstance GetPrototypeFromConstructor(JsValue constructor, Func<Intrinsics, ObjectInstance> intrinsicDefaultProto)
         {
-            var proto = constructor.Get(CommonProperties.Prototype, constructor) as ObjectInstance;
-            if (proto is null)
+            if (constructor.Get(CommonProperties.Prototype, constructor) is not ObjectInstance proto)
             {
                 var realm = GetFunctionRealm(constructor);
                 proto = intrinsicDefaultProto(realm.Intrinsics);
@@ -354,7 +353,7 @@ namespace Jint.Native.Function
             return _engine.EnterExecutionContext(calleeContext);
         }
 
-        internal void MakeConstructor(bool writableProperty = true, ObjectInstance prototype = null)
+        internal void MakeConstructor(bool writableProperty = true, ObjectInstance? prototype = null)
         {
             _constructorKind = ConstructorKind.Base;
             if (prototype is null)
@@ -387,7 +386,7 @@ namespace Jint.Native.Function
 
         private sealed class ObjectInstanceWithConstructor : ObjectInstance
         {
-            private PropertyDescriptor _constructor;
+            private PropertyDescriptor? _constructor;
 
             public ObjectInstanceWithConstructor(Engine engine, ObjectInstance thisObj) : base(engine)
             {

+ 1 - 1
Jint/Native/Function/FunctionKind.cs

@@ -7,4 +7,4 @@ namespace Jint.Native.Function
         Generator,
         AsyncGenerator
     }
-}
+}

+ 1 - 1
Jint/Native/Function/FunctionPrototype.cs

@@ -1,4 +1,4 @@
-using Jint.Collections;
+using Jint.Collections;
 using Jint.Native.Array;
 using Jint.Native.Object;
 using Jint.Native.Symbol;

+ 1 - 1
Jint/Native/Function/FunctionThisMode.cs

@@ -6,4 +6,4 @@ namespace Jint.Native.Function
         Strict,
         Global
     }
-}
+}

+ 5 - 5
Jint/Native/Function/ScriptFunctionInstance.cs

@@ -1,4 +1,4 @@
-using Esprima.Ast;
+using Esprima.Ast;
 using Jint.Native.Object;
 using Jint.Runtime;
 using Jint.Runtime.Descriptors;
@@ -20,7 +20,7 @@ namespace Jint.Native.Function
             IFunction functionDeclaration,
             EnvironmentRecord scope,
             bool strict,
-            ObjectInstance proto = null)
+            ObjectInstance? proto = null)
             : this(
                 engine,
                 new JintFunctionDefinition(engine, functionDeclaration),
@@ -35,7 +35,7 @@ namespace Jint.Native.Function
             JintFunctionDefinition function,
             EnvironmentRecord scope,
             FunctionThisMode thisMode,
-            ObjectInstance proto = null)
+            ObjectInstance? proto = null)
             : base(engine, engine.Realm, function, scope, thisMode)
         {
             _prototype = proto ?? _engine.Realm.Intrinsics.Function.PrototypeObject;
@@ -107,7 +107,7 @@ namespace Jint.Native.Function
         internal override bool IsConstructor =>
             (_homeObject.IsUndefined() || _isClassConstructor)
             && _functionDefinition?.Function is not ArrowFunctionExpression
-            && _functionDefinition?.Function.Generator != true;
+            && _functionDefinition?.Function?.Generator != true;
 
         /// <summary>
         /// https://tc39.es/ecma262/#sec-ecmascript-function-objects-construct-argumentslist-newtarget
@@ -124,7 +124,7 @@ namespace Jint.Native.Function
                 thisArgument = OrdinaryCreateFromConstructor(
                     newTarget,
                     static intrinsics => intrinsics.Object.PrototypeObject,
-                    static (Engine engine, Realm _, object _) => new ObjectInstance(engine));
+                    static (Engine engine, Realm _, object? _) => new ObjectInstance(engine));
             }
 
             var calleeContext = PrepareForOrdinaryCall(newTarget);

+ 1 - 1
Jint/Native/Function/ThrowTypeError.cs

@@ -1,4 +1,4 @@
-using Jint.Runtime;
+using Jint.Runtime;
 using Jint.Runtime.Descriptors;
 
 namespace Jint.Native.Function

+ 1 - 1
Jint/Native/Generator/GeneratorKind.cs

@@ -6,4 +6,4 @@ namespace Jint.Native.Generator
         Sync,
         Async
     }
-}
+}

+ 56 - 56
Jint/Native/Global/GlobalObject.cs

@@ -1,4 +1,4 @@
-using System.Globalization;
+using System.Globalization;
 using System.Runtime.CompilerServices;
 using System.Text;
 using Jint.Collections;
@@ -32,98 +32,98 @@ namespace Jint.Native.Global
 
             var properties = new PropertyDictionary(55, checkExistingKeys: false)
             {
-                ["AggregateError"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state)._realm.Intrinsics.AggregateError, propertyFlags),
-                ["Array"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state)._realm.Intrinsics.Array, propertyFlags),
-                ["ArrayBuffer"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state)._realm.Intrinsics.ArrayBuffer, propertyFlags),
+                ["AggregateError"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state!)._realm.Intrinsics.AggregateError, propertyFlags),
+                ["Array"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state!)._realm.Intrinsics.Array, propertyFlags),
+                ["ArrayBuffer"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state!)._realm.Intrinsics.ArrayBuffer, propertyFlags),
                 ["Atomics"] = new LazyPropertyDescriptor(this, static state => Undefined, propertyFlags),
-                ["BigInt"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state)._realm.Intrinsics.BigInt, propertyFlags),
-                ["BigInt64Array"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state)._realm.Intrinsics.BigInt64Array, propertyFlags),
-                ["BigUint64Array"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state)._realm.Intrinsics.BigUint64Array, propertyFlags),
-                ["Boolean"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state)._realm.Intrinsics.Boolean, propertyFlags),
-                ["DataView"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state)._realm.Intrinsics.DataView, propertyFlags),
-                ["Date"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state)._realm.Intrinsics.Date, propertyFlags),
-                ["Error"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state)._realm.Intrinsics.Error, propertyFlags),
-                ["EvalError"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state)._realm.Intrinsics.EvalError, propertyFlags),
+                ["BigInt"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state!)._realm.Intrinsics.BigInt, propertyFlags),
+                ["BigInt64Array"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state!)._realm.Intrinsics.BigInt64Array, propertyFlags),
+                ["BigUint64Array"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state!)._realm.Intrinsics.BigUint64Array, propertyFlags),
+                ["Boolean"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state!)._realm.Intrinsics.Boolean, propertyFlags),
+                ["DataView"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state!)._realm.Intrinsics.DataView, propertyFlags),
+                ["Date"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state!)._realm.Intrinsics.Date, propertyFlags),
+                ["Error"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state!)._realm.Intrinsics.Error, propertyFlags),
+                ["EvalError"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state!)._realm.Intrinsics.EvalError, propertyFlags),
                 ["FinalizationRegistry"] = new LazyPropertyDescriptor(this, static state => Undefined, propertyFlags),
-                ["Float32Array"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state)._realm.Intrinsics.Float32Array, propertyFlags),
-                ["Float64Array"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state)._realm.Intrinsics.Float64Array, propertyFlags),
+                ["Float32Array"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state!)._realm.Intrinsics.Float32Array, propertyFlags),
+                ["Float64Array"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state!)._realm.Intrinsics.Float64Array, propertyFlags),
                 ["Function"] = new PropertyDescriptor(_realm.Intrinsics.Function, propertyFlags),
-                ["Int16Array"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state)._realm.Intrinsics.Int16Array, propertyFlags),
-                ["Int32Array"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state)._realm.Intrinsics.Int32Array, propertyFlags),
-                ["Int8Array"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state)._realm.Intrinsics.Int8Array, propertyFlags),
-                ["JSON"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state)._realm.Intrinsics.Json, propertyFlags),
-                ["Map"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state)._realm.Intrinsics.Map, propertyFlags),
-                ["Math"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state)._realm.Intrinsics.Math, propertyFlags),
-                ["Number"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state)._realm.Intrinsics.Number, propertyFlags),
+                ["Int16Array"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state!)._realm.Intrinsics.Int16Array, propertyFlags),
+                ["Int32Array"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state!)._realm.Intrinsics.Int32Array, propertyFlags),
+                ["Int8Array"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state!)._realm.Intrinsics.Int8Array, propertyFlags),
+                ["JSON"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state!)._realm.Intrinsics.Json, propertyFlags),
+                ["Map"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state!)._realm.Intrinsics.Map, propertyFlags),
+                ["Math"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state!)._realm.Intrinsics.Math, propertyFlags),
+                ["Number"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state!)._realm.Intrinsics.Number, propertyFlags),
                 ["Object"] = new PropertyDescriptor(_realm.Intrinsics.Object, propertyFlags),
-                ["Promise"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state)._realm.Intrinsics.Promise, propertyFlags),
-                ["Proxy"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state)._realm.Intrinsics.Proxy, propertyFlags),
-                ["RangeError"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state)._realm.Intrinsics.RangeError, propertyFlags),
-                ["ReferenceError"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state)._realm.Intrinsics.ReferenceError, propertyFlags),
-                ["Reflect"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state)._realm.Intrinsics.Reflect, propertyFlags),
-                ["RegExp"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state)._realm.Intrinsics.RegExp, propertyFlags),
-                ["Set"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state)._realm.Intrinsics.Set, propertyFlags),
-                ["ShadowRealm"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state)._realm.Intrinsics.ShadowRealm, propertyFlags),
+                ["Promise"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state!)._realm.Intrinsics.Promise, propertyFlags),
+                ["Proxy"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state!)._realm.Intrinsics.Proxy, propertyFlags),
+                ["RangeError"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state!)._realm.Intrinsics.RangeError, propertyFlags),
+                ["ReferenceError"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state!)._realm.Intrinsics.ReferenceError, propertyFlags),
+                ["Reflect"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state!)._realm.Intrinsics.Reflect, propertyFlags),
+                ["RegExp"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state!)._realm.Intrinsics.RegExp, propertyFlags),
+                ["Set"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state!)._realm.Intrinsics.Set, propertyFlags),
+                ["ShadowRealm"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state!)._realm.Intrinsics.ShadowRealm, propertyFlags),
                 ["SharedArrayBuffer"] = new LazyPropertyDescriptor(this, static state => Undefined, propertyFlags),
-                ["String"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state)._realm.Intrinsics.String, propertyFlags),
-                ["Symbol"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state)._realm.Intrinsics.Symbol, propertyFlags),
-                ["SyntaxError"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state)._realm.Intrinsics.SyntaxError, propertyFlags),
-                ["TypeError"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state)._realm.Intrinsics.TypeError, propertyFlags),
-                ["TypedArray"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state)._realm.Intrinsics.TypedArray, propertyFlags),
-                ["URIError"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state)._realm.Intrinsics.UriError, propertyFlags),
-                ["Uint16Array"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state)._realm.Intrinsics.Uint16Array, propertyFlags),
-                ["Uint32Array"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state)._realm.Intrinsics.Uint32Array, propertyFlags),
-                ["Uint8Array"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state)._realm.Intrinsics.Uint8Array, propertyFlags),
-                ["Uint8ClampedArray"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state)._realm.Intrinsics.Uint8ClampedArray, propertyFlags),
-                ["WeakMap"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state)._realm.Intrinsics.WeakMap, propertyFlags),
+                ["String"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state!)._realm.Intrinsics.String, propertyFlags),
+                ["Symbol"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state!)._realm.Intrinsics.Symbol, propertyFlags),
+                ["SyntaxError"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state!)._realm.Intrinsics.SyntaxError, propertyFlags),
+                ["TypeError"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state!)._realm.Intrinsics.TypeError, propertyFlags),
+                ["TypedArray"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state!)._realm.Intrinsics.TypedArray, propertyFlags),
+                ["URIError"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state!)._realm.Intrinsics.UriError, propertyFlags),
+                ["Uint16Array"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state!)._realm.Intrinsics.Uint16Array, propertyFlags),
+                ["Uint32Array"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state!)._realm.Intrinsics.Uint32Array, propertyFlags),
+                ["Uint8Array"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state!)._realm.Intrinsics.Uint8Array, propertyFlags),
+                ["Uint8ClampedArray"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state!)._realm.Intrinsics.Uint8ClampedArray, propertyFlags),
+                ["WeakMap"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state!)._realm.Intrinsics.WeakMap, propertyFlags),
                 ["WeakRef"] = new LazyPropertyDescriptor(this, static state => Undefined, propertyFlags),
-                ["WeakSet"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state)._realm.Intrinsics.WeakSet, propertyFlags),
+                ["WeakSet"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state!)._realm.Intrinsics.WeakSet, propertyFlags),
 
 
                 ["NaN"] = new PropertyDescriptor(double.NaN, PropertyFlag.AllForbidden),
                 ["Infinity"] = new PropertyDescriptor(double.PositiveInfinity, PropertyFlag.AllForbidden),
                 ["undefined"] = new PropertyDescriptor(Undefined, PropertyFlag.AllForbidden),
-                ["parseInt"] = new LazyPropertyDescriptor(this, static state => new ClrFunctionInstance(((GlobalObject) state)._engine, "parseInt", ParseInt, 2, lengthFlags), propertyFlags),
-                ["parseFloat"] = new LazyPropertyDescriptor(this, static state => new ClrFunctionInstance(((GlobalObject) state)._engine, "parseFloat", ParseFloat, 1, lengthFlags), propertyFlags),
-                ["isNaN"] = new LazyPropertyDescriptor(this, static state => new ClrFunctionInstance(((GlobalObject) state)._engine, "isNaN", IsNaN, 1, lengthFlags), propertyFlags),
-                ["isFinite"] = new LazyPropertyDescriptor(this, static state => new ClrFunctionInstance(((GlobalObject) state)._engine, "isFinite", IsFinite, 1, lengthFlags), propertyFlags),
+                ["parseInt"] = new LazyPropertyDescriptor(this, static state => new ClrFunctionInstance(((GlobalObject) state!)._engine, "parseInt", ParseInt, 2, lengthFlags), propertyFlags),
+                ["parseFloat"] = new LazyPropertyDescriptor(this, static state => new ClrFunctionInstance(((GlobalObject) state!)._engine, "parseFloat", ParseFloat, 1, lengthFlags), propertyFlags),
+                ["isNaN"] = new LazyPropertyDescriptor(this, static state => new ClrFunctionInstance(((GlobalObject) state!)._engine, "isNaN", IsNaN, 1, lengthFlags), propertyFlags),
+                ["isFinite"] = new LazyPropertyDescriptor(this, static state => new ClrFunctionInstance(((GlobalObject) state!)._engine, "isFinite", IsFinite, 1, lengthFlags), propertyFlags),
                 ["decodeURI"] = new LazyPropertyDescriptor(this, static state =>
                 {
-                    var global = (GlobalObject) state;
+                    var global = (GlobalObject) state!;
                     return new ClrFunctionInstance(global._engine, "decodeURI", global.DecodeUri, 1, lengthFlags);
                 }, propertyFlags),
                 ["decodeURIComponent"] = new LazyPropertyDescriptor(this, static state =>
                 {
-                    var global = (GlobalObject) state;
+                    var global = (GlobalObject) state!;
                     return new ClrFunctionInstance(global._engine, "decodeURIComponent", global.DecodeUriComponent, 1, lengthFlags);
                 }, propertyFlags),
                 ["encodeURI"] = new LazyPropertyDescriptor(this, static state =>
                 {
-                    var global = (GlobalObject) state;
+                    var global = (GlobalObject) state!;
                     return new ClrFunctionInstance(global._engine, "encodeURI", global.EncodeUri, 1, lengthFlags);
                 }, propertyFlags),
                 ["encodeURIComponent"] = new LazyPropertyDescriptor(this, static state =>
                 {
-                    var global = (GlobalObject) state;
+                    var global = (GlobalObject) state!;
                     return new ClrFunctionInstance(global._engine, "encodeURIComponent", global.EncodeUriComponent, 1, lengthFlags);
                 }, propertyFlags),
                 ["escape"] = new LazyPropertyDescriptor(this, static state =>
                 {
-                    var global = (GlobalObject) state;
+                    var global = (GlobalObject) state!;
                     return new ClrFunctionInstance(global._engine, "escape", global.Escape, 1, lengthFlags);
                 }, propertyFlags),
                 ["unescape"] = new LazyPropertyDescriptor(this, static state =>
                 {
-                    var global = (GlobalObject) state;
+                    var global = (GlobalObject) state!;
                     return new ClrFunctionInstance(global._engine, "unescape", global.Unescape, 1, lengthFlags);
                 }, propertyFlags),
                 ["globalThis"] = new PropertyDescriptor(this, propertyFlags),
-                ["eval"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state)._realm.Intrinsics.Eval, PropertyFlag.Configurable | PropertyFlag.Writable),
+                ["eval"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state!)._realm.Intrinsics.Eval, PropertyFlag.Configurable | PropertyFlag.Writable),
 
                 // toString is not mentioned or actually required in spec, but some tests rely on it
                 ["toString"] = new LazyPropertyDescriptor(this, static state =>
                 {
-                    var global = (GlobalObject) state;
+                    var global = (GlobalObject) state!;
                     return new ClrFunctionInstance(global._engine, "toString", global.ToStringString, 1);
                 }, propertyFlags)
             };
@@ -579,7 +579,7 @@ namespace Jint.Native.Global
             return Decode(componentString, null);
         }
 
-        private string Decode(string uriString, HashSet<char> reservedSet)
+        private string Decode(string uriString, HashSet<char>? reservedSet)
         {
             var strLen = uriString.Length;
 
@@ -794,7 +794,7 @@ namespace Jint.Native.Global
         [MethodImpl(MethodImplOptions.AggressiveInlining)]
         internal PropertyDescriptor GetOwnProperty(Key property)
         {
-            Properties.TryGetValue(property, out var descriptor);
+            Properties!.TryGetValue(property, out var descriptor);
             return descriptor ?? PropertyDescriptor.Undefined;
         }
 
@@ -803,7 +803,7 @@ namespace Jint.Native.Global
             // here we are called only from global environment record context
             // we can take some shortcuts to be faster
 
-            if (!_properties.TryGetValue(property, out var existingDescriptor))
+            if (!_properties!.TryGetValue(property, out var existingDescriptor))
             {
                 _properties[property] = new PropertyDescriptor(value, PropertyFlag.ConfigurableEnumerableWritable);
                 return true;

+ 1 - 1
Jint/Native/ICallable.cs

@@ -1,4 +1,4 @@
-namespace Jint.Native
+namespace Jint.Native
 {
     internal interface ICallable
     {

+ 1 - 1
Jint/Native/IConstructor.cs

@@ -1,4 +1,4 @@
-using Jint.Native.Object;
+using Jint.Native.Object;
 
 namespace Jint.Native
 {

+ 1 - 1
Jint/Native/IPrimitiveInstance.cs

@@ -1,4 +1,4 @@
-using Jint.Runtime;
+using Jint.Runtime;
 
 namespace Jint.Native
 {

+ 1 - 1
Jint/Native/Iterator/ArrayIteratorType.cs

@@ -6,4 +6,4 @@ namespace Jint.Native.Iterator
         Value,
         KeyAndValue
     }
-}
+}

+ 8 - 7
Jint/Native/Iterator/IteratorInstance.cs

@@ -29,7 +29,7 @@ namespace Jint.Native.Iterator
             return null;
         }
 
-        public override bool Equals(JsValue other)
+        public override bool Equals(JsValue? other)
         {
             return false;
         }
@@ -62,14 +62,14 @@ namespace Jint.Native.Iterator
         {
             internal static ObjectInstance Done(Engine engine) => new KeyValueIteratorPosition(engine, null, null);
 
-            public KeyValueIteratorPosition(Engine engine, JsValue key, JsValue value) : base(engine)
+            public KeyValueIteratorPosition(Engine engine, JsValue? key, JsValue? value) : base(engine)
             {
                 var done = ReferenceEquals(null, key) && ReferenceEquals(null, value);
                 if (!done)
                 {
                     var arrayInstance = engine.Realm.Intrinsics.Array.ArrayCreate(2);
-                    arrayInstance.SetIndexValue(0, key, false);
-                    arrayInstance.SetIndexValue(1, value, false);
+                    arrayInstance.SetIndexValue(0, key!, false);
+                    arrayInstance.SetIndexValue(1, value!, false);
                     SetProperty("value", new PropertyDescriptor(arrayInstance, PropertyFlag.AllForbidden));
                 }
                 SetProperty("done", done ? PropertyDescriptor.AllForbiddenDescriptor.BooleanTrue : PropertyDescriptor.AllForbiddenDescriptor.BooleanFalse);
@@ -78,7 +78,7 @@ namespace Jint.Native.Iterator
 
         internal sealed class ValueIteratorPosition : ObjectInstance
         {
-            internal static ObjectInstance Done(Engine engine, JsValue value = null)
+            internal static ObjectInstance Done(Engine engine, JsValue? value = null)
                 => new ValueIteratorPosition(engine, value ?? Undefined, true);
 
             public ValueIteratorPosition(Engine engine, JsValue value, bool? done = null) : base(engine)
@@ -127,11 +127,12 @@ namespace Jint.Native.Iterator
             public ObjectIterator(ObjectInstance target) : base(target.Engine)
             {
                 _target = target;
-                _nextMethod = target.Get(CommonProperties.Next, target) as ICallable;
-                if (_nextMethod is null)
+                if (target.Get(CommonProperties.Next, target) is not ICallable callable)
                 {
                     ExceptionHelper.ThrowTypeError(target.Engine.Realm);
+                    return;
                 }
+                _nextMethod = callable;
             }
 
             public override bool TryIteratorStep(out ObjectInstance result)

+ 2 - 2
Jint/Native/Iterator/IteratorProtocol.cs

@@ -1,4 +1,4 @@
-using Jint.Native.Object;
+using Jint.Native.Object;
 using Jint.Runtime;
 
 namespace Jint.Native.Iterator
@@ -120,4 +120,4 @@ namespace Jint.Native.Iterator
             }
         }
     }
-}
+}

+ 3 - 3
Jint/Native/Iterator/IteratorPrototype.cs

@@ -1,4 +1,4 @@
-using Jint.Collections;
+using Jint.Collections;
 using Jint.Native.Symbol;
 using Jint.Runtime;
 using Jint.Runtime.Descriptors;
@@ -11,12 +11,12 @@ namespace Jint.Native.Iterator
     /// </summary>
     internal class IteratorPrototype : Prototype
     {
-        private readonly string _name;
+        private readonly string? _name;
 
         internal IteratorPrototype(
             Engine engine,
             Realm realm,
-            string name,
+            string? name,
             Prototype objectPrototype) : base(engine, realm)
         {
             _prototype = objectPrototype;

+ 2 - 2
Jint/Native/Iterator/IteratorResult.cs

@@ -37,9 +37,9 @@ namespace Jint.Native.Iterator
             return this;
         }
 
-        public override bool Equals(JsValue other)
+        public override bool Equals(JsValue? other)
         {
             return ReferenceEquals(this, other);
         }
     }
-}
+}

+ 2 - 2
Jint/Native/JsBigInt.cs

@@ -101,12 +101,12 @@ public sealed class JsBigInt : JsValue, IEquatable<JsBigInt>
         return Equals(other as JsBigInt);
     }
 
-    public override bool Equals(JsValue other)
+    public override bool Equals(JsValue? other)
     {
         return Equals(other as JsBigInt);
     }
 
-    public bool Equals(JsBigInt other)
+    public bool Equals(JsBigInt? other)
     {
         if (ReferenceEquals(null, other))
         {

+ 1 - 3
Jint/Native/JsBoolean.cs

@@ -1,5 +1,3 @@
-#nullable enable
-
 using Jint.Runtime;
 
 namespace Jint.Native
@@ -39,7 +37,7 @@ namespace Jint.Native
             return !value.IsNullOrUndefined() && base.IsLooselyEqual(value);
         }
 
-        public override bool Equals(JsValue obj)
+        public override bool Equals(JsValue? obj)
         {
             return Equals(obj as JsBoolean);
         }

+ 3 - 5
Jint/Native/JsNull.cs

@@ -1,5 +1,3 @@
-#nullable enable
-
 using Jint.Runtime;
 
 namespace Jint.Native
@@ -10,9 +8,9 @@ namespace Jint.Native
         {
         }
 
-        public override object? ToObject()
+        public override object ToObject()
         {
-            return null;
+            return null!;
         }
 
         public override string ToString()
@@ -25,7 +23,7 @@ namespace Jint.Native
             return ReferenceEquals(Null, value) || ReferenceEquals(Undefined, value);
         }
 
-        public override bool Equals(JsValue obj)
+        public override bool Equals(JsValue? obj)
         {
             return Equals(obj as JsNull);
         }

+ 1 - 3
Jint/Native/JsNumber.cs

@@ -1,5 +1,3 @@
-#nullable enable
-
 using System.Numerics;
 using System.Runtime.CompilerServices;
 using Jint.Native.Number;
@@ -263,7 +261,7 @@ namespace Jint.Native
             return base.IsLooselyEqual(value);
         }
 
-        public override bool Equals(JsValue obj)
+        public override bool Equals(JsValue? obj)
         {
             return Equals(obj as JsNumber);
         }

+ 2 - 4
Jint/Native/JsString.cs

@@ -1,5 +1,3 @@
-#nullable enable
-
 using System.Text;
 using Jint.Native.Array;
 using Jint.Runtime;
@@ -230,7 +228,7 @@ namespace Jint.Native
             return ToString().Substring(startIndex);
         }
 
-        public override bool Equals(JsValue obj)
+        public override bool Equals(JsValue? obj)
         {
             return Equals(obj as JsString);
         }
@@ -336,7 +334,7 @@ namespace Jint.Native
 
             public override object ToObject() => ToString();
 
-            public override bool Equals(JsValue other)
+            public override bool Equals(JsValue? other)
             {
                 if (other is ConcatenatedString cs)
                 {

+ 3 - 3
Jint/Native/JsSymbol.cs

@@ -1,4 +1,4 @@
-using System.Runtime.CompilerServices;
+using System.Runtime.CompilerServices;
 using Jint.Runtime;
 
 namespace Jint.Native
@@ -33,12 +33,12 @@ namespace Jint.Native
             return "Symbol(" + value + ")";
         }
 
-        public override bool Equals(JsValue obj)
+        public override bool Equals(JsValue? obj)
         {
             return Equals(obj as JsSymbol);
         }
 
-        public bool Equals(JsSymbol other)
+        public bool Equals(JsSymbol? other)
         {
             return ReferenceEquals(this, other);
         }

+ 4 - 4
Jint/Native/JsUndefined.cs

@@ -1,4 +1,4 @@
-using Jint.Runtime;
+using Jint.Runtime;
 
 namespace Jint.Native
 {
@@ -10,7 +10,7 @@ namespace Jint.Native
 
         public override object ToObject()
         {
-            return null;
+            return null!;
         }
 
         public override string ToString()
@@ -23,12 +23,12 @@ namespace Jint.Native
             return ReferenceEquals(Undefined, value) || ReferenceEquals(Null, value);
         }
 
-        public override bool Equals(JsValue obj)
+        public override bool Equals(JsValue? obj)
         {
             return Equals(obj as JsUndefined);
         }
 
-        public bool Equals(JsUndefined other)
+        public bool Equals(JsUndefined? other)
         {
             return !ReferenceEquals(null, other);
         }

+ 14 - 16
Jint/Native/JsValue.cs

@@ -1,4 +1,5 @@
-using System.Diagnostics;
+using System.Diagnostics;
+using System.Diagnostics.CodeAnalysis;
 using System.Diagnostics.Contracts;
 using System.Numerics;
 using System.Runtime.CompilerServices;
@@ -37,11 +38,12 @@ namespace Jint.Native
 
         [Pure]
         [MethodImpl(MethodImplOptions.AggressiveInlining)]
-        internal IteratorInstance GetIterator(Realm realm, GeneratorKind hint = GeneratorKind.Sync, ICallable method = null)
+        internal IteratorInstance GetIterator(Realm realm, GeneratorKind hint = GeneratorKind.Sync, ICallable? method = null)
         {
             if (!TryGetIterator(realm, out var iterator, hint, method))
             {
                 ExceptionHelper.ThrowTypeError(realm, "The value is not iterable");
+                return null!;
             }
 
             return iterator;
@@ -49,7 +51,7 @@ namespace Jint.Native
 
         [Pure]
         [MethodImpl(MethodImplOptions.AggressiveInlining)]
-        internal bool TryGetIterator(Realm realm, out IteratorInstance iterator, GeneratorKind hint = GeneratorKind.Sync, ICallable method = null)
+        internal bool TryGetIterator(Realm realm, [NotNullWhen(true)] out IteratorInstance? iterator, GeneratorKind hint = GeneratorKind.Sync, ICallable? method = null)
         {
             var obj = TypeConverter.ToObject(realm, this);
 
@@ -107,7 +109,7 @@ namespace Jint.Native
         /// <summary>
         /// Creates a valid <see cref="JsValue"/> instance from any <see cref="Object"/> instance
         /// </summary>
-        public static JsValue FromObject(Engine engine, object value)
+        public static JsValue FromObject(Engine engine, object? value)
         {
             if (value is null)
             {
@@ -135,7 +137,7 @@ namespace Jint.Native
                 return defaultConversion;
             }
 
-            return null;
+            return null!;
         }
 
         /// <summary>
@@ -209,7 +211,7 @@ namespace Jint.Native
             return "None";
         }
 
-        public static bool operator ==(JsValue a, JsValue b)
+        public static bool operator ==(JsValue? a, JsValue? b)
         {
             if (a is null)
             {
@@ -219,7 +221,7 @@ namespace Jint.Native
             return b is not null && a.Equals(b);
         }
 
-        public static bool operator !=(JsValue a, JsValue b)
+        public static bool operator !=(JsValue? a, JsValue? b)
         {
             return !(a == b);
         }
@@ -265,14 +267,9 @@ namespace Jint.Native
         }
 
         [DebuggerStepThrough]
-        public static implicit operator JsValue(string value)
+        public static implicit operator JsValue(string? value)
         {
-            if (value == null)
-            {
-                return Null;
-            }
-
-            return JsString.Create(value);
+            return value == null ? Null : JsString.Create(value);
         }
 
         /// <summary>
@@ -334,7 +331,7 @@ namespace Jint.Native
         /// <summary>
         /// Strict equality.
         /// </summary>
-        public virtual bool Equals(JsValue other)
+        public virtual bool Equals(JsValue? other)
         {
             return ReferenceEquals(this, other);
         }
@@ -416,7 +413,8 @@ namespace Jint.Native
                 return false;
             }
 
-            if (v is not ObjectInstance o)
+            var o = v as ObjectInstance;
+            if (o is null)
             {
                 return false;
             }

+ 1 - 1
Jint/Native/Json/JsonInstance.cs

@@ -1,4 +1,4 @@
-using Jint.Collections;
+using Jint.Collections;
 using Jint.Native.Object;
 using Jint.Native.Symbol;
 using Jint.Runtime;

+ 17 - 17
Jint/Native/Json/JsonParser.cs

@@ -15,15 +15,15 @@ namespace Jint.Native.Json
             _engine = engine;
         }
 
-        private Extra _extra;
+        private Extra _extra = null!;
 
         private int _index; // position in the stream
         private int _length; // length of the stream
         private int _lineNumber;
         private int _lineStart;
         private Location _location;
-        private Token _lookahead;
-        private string _source;
+        private Token _lookahead = null!;
+        private string _source = null!;
 
         private State _state;
 
@@ -152,7 +152,7 @@ namespace Jint.Native.Json
             }
 
             ThrowError(start, Messages.UnexpectedToken, code);
-            return null;
+            return null!;
         }
 
         private Token ScanNumericLiteral()
@@ -259,7 +259,7 @@ namespace Jint.Native.Json
             }
 
             ThrowError(start, Messages.UnexpectedToken, s);
-            return null;
+            return null!;
         }
 
         private Token ScanNullLiteral()
@@ -286,7 +286,7 @@ namespace Jint.Native.Json
             }
 
             ThrowError(start, Messages.UnexpectedToken, s);
-            return null;
+            return null!;
         }
 
         private Token ScanStringLiteral()
@@ -465,7 +465,7 @@ namespace Jint.Native.Json
             {
                 var range = new[] {token.Range[0], token.Range[1]};
                 string value = _source.Slice(token.Range[0], token.Range[1]);
-                _extra.Tokens.Add(new Token
+                _extra!.Tokens.Add(new Token
                     {
                         Type = token.Type,
                         Text = value,
@@ -479,7 +479,7 @@ namespace Jint.Native.Json
 
         private Token Lex()
         {
-            Token token = _lookahead;
+            Token token = _lookahead!;
             _index = token.Range[1];
             _lineNumber = token.LineNumber.HasValue ? token.LineNumber.Value : 0;
             _lineStart = token.LineStart;
@@ -659,7 +659,7 @@ namespace Jint.Native.Json
 
             while (!Match("}"))
             {
-                Tokens type = _lookahead.Type;
+                Tokens type = _lookahead!.Type;
                 if (type != Tokens.String)
                 {
                     ThrowUnexpected(Lex());
@@ -747,14 +747,14 @@ namespace Jint.Native.Json
             return Parse(code, null);
         }
 
-        public JsValue Parse(string code, ParserOptions options)
+        public JsValue Parse(string code, ParserOptions? options)
         {
             _source = code;
             _index = 0;
             _lineNumber = 1;
             _lineStart = 0;
             _length = _source.Length;
-            _lookahead = null;
+            _lookahead = null!;
             _state = new State
             {
                 AllowIn = true,
@@ -790,7 +790,7 @@ namespace Jint.Native.Json
 
                 Peek();
 
-                if(_lookahead.Type != Tokens.EOF)
+                if(_lookahead!.Type != Tokens.EOF)
                 {
                     ThrowError(_lookahead, Messages.UnexpectedToken, _lookahead.Text);
                 }
@@ -805,9 +805,9 @@ namespace Jint.Native.Json
         private sealed class Extra
         {
             public int? Loc;
-            public int[] Range;
+            public int[]? Range;
 
-            public List<Token> Tokens;
+            public List<Token> Tokens = null!;
         }
 
         private enum Tokens
@@ -823,9 +823,9 @@ namespace Jint.Native.Json
         class Token
         {
             public Tokens Type;
-            public object Value;
-            public string Text;
-            public int[] Range;
+            public object Value = null!;
+            public string Text = null!;
+            public int[] Range = null!;
             public int? LineNumber;
             public int LineStart;
         }

+ 6 - 5
Jint/Native/Json/JsonSerializer.cs

@@ -1,4 +1,4 @@
-using Jint.Collections;
+using Jint.Collections;
 using Jint.Native.Array;
 using Jint.Native.BigInt;
 using Jint.Native.Boolean;
@@ -17,9 +17,10 @@ namespace Jint.Native.Json
     public class JsonSerializer
     {
         private readonly Engine _engine;
-        private ObjectTraverseStack _stack;
-        private string _indent, _gap;
-        private List<JsValue> _propertyList;
+        private ObjectTraverseStack _stack = null!;
+        private string? _indent;
+        private string? _gap;
+        private List<JsValue>? _propertyList;
         private JsValue _replacerFunction = Undefined.Instance;
 
         private static readonly JsString toJsonProperty = new("toJSON");
@@ -355,7 +356,7 @@ namespace Jint.Native.Json
             var stepback = _indent;
             _indent += _gap;
 
-            var k = (IEnumerable<JsValue>) _propertyList ?? value.EnumerableOwnPropertyNames(ObjectInstance.EnumerableOwnPropertyNamesKind.Key);
+            var k = (IEnumerable<JsValue>?) _propertyList ?? value.EnumerableOwnPropertyNames(ObjectInstance.EnumerableOwnPropertyNamesKind.Key);
 
             var partial = new List<string>();
             foreach (var p in k)

+ 3 - 3
Jint/Native/Map/MapConstructor.cs

@@ -1,4 +1,4 @@
-using Jint.Collections;
+using Jint.Collections;
 using Jint.Native.Function;
 using Jint.Native.Iterator;
 using Jint.Native.Object;
@@ -61,8 +61,8 @@ namespace Jint.Native.Map
             var map = OrdinaryCreateFromConstructor(
                 newTarget,
                 static intrinsics => intrinsics.Map.PrototypeObject,
-                static (Engine engine, Realm realm, object _) => new MapInstance(engine, realm));
-            
+                static (Engine engine, Realm realm, object? _) => new MapInstance(engine, realm));
+
             if (arguments.Length > 0 && !arguments[0].IsNullOrUndefined())
             {
                 var adder = map.Get("set");

+ 3 - 2
Jint/Native/Map/MapInstance.cs

@@ -1,4 +1,5 @@
-using System.Runtime.CompilerServices;
+using System.Diagnostics.CodeAnalysis;
+using System.Runtime.CompilerServices;
 using Jint.Native.Object;
 using Jint.Runtime;
 using Jint.Runtime.Descriptors;
@@ -26,7 +27,7 @@ namespace Jint.Native.Map
             return base.GetOwnProperty(property);
         }
 
-        protected override bool TryGetProperty(JsValue property, out PropertyDescriptor descriptor)
+        protected override bool TryGetProperty(JsValue property, [NotNullWhen(true)] out PropertyDescriptor? descriptor)
         {
             if (property == CommonProperties.Size)
             {

+ 1 - 1
Jint/Native/Map/MapIteratorPrototype.cs

@@ -75,4 +75,4 @@ namespace Jint.Native.Map
             }
         }
     }
-}
+}

+ 2 - 2
Jint/Native/Map/MapPrototype.cs

@@ -1,4 +1,4 @@
-using Jint.Collections;
+using Jint.Collections;
 using Jint.Native.Object;
 using Jint.Native.Symbol;
 using Jint.Runtime;
@@ -136,4 +136,4 @@ namespace Jint.Native.Map
             return map;
         }
     }
-}
+}

+ 2 - 2
Jint/Native/Math/MathInstance.cs

@@ -1,4 +1,4 @@
-using Jint.Collections;
+using Jint.Collections;
 using Jint.Native.Number;
 using Jint.Native.Object;
 using Jint.Native.Symbol;
@@ -10,7 +10,7 @@ namespace Jint.Native.Math
 {
     public sealed class MathInstance : ObjectInstance
     {
-        private Random _random;
+        private Random? _random;
 
         internal MathInstance(Engine engine, ObjectPrototype objectPrototype) : base(engine)
         {

+ 2 - 2
Jint/Native/Null.cs

@@ -1,8 +1,8 @@
-namespace Jint.Native
+namespace Jint.Native
 {
     public static class Null
     {
         public static readonly JsValue Instance = JsValue.Null;
         public const string Text = "null";
     }
-}
+}

+ 2 - 0
Jint/Native/Number/Dtoa/Bignum.cs

@@ -1,3 +1,5 @@
+#nullable disable
+
 using System.Diagnostics;
 using Jint.Runtime;
 

+ 2 - 0
Jint/Native/Number/Dtoa/BignumDtoa.cs

@@ -1,3 +1,5 @@
+#nullable disable
+
 using System.Diagnostics;
 using Jint.Runtime;
 

+ 3 - 1
Jint/Native/Number/Dtoa/CachePowers.cs

@@ -1,4 +1,6 @@
-// Copyright 2010 the V8 project authors. All rights reserved.
+#nullable disable
+
+// Copyright 2010 the V8 project authors. All rights reserved.
 // Redistribution and use in source and binary forms, with or without
 // modification, are permitted provided that the following conditions are
 // met:

+ 3 - 1
Jint/Native/Number/Dtoa/DiyFp.cs

@@ -1,4 +1,6 @@
-// Copyright 2010 the V8 project authors. All rights reserved.
+#nullable disable
+
+// Copyright 2010 the V8 project authors. All rights reserved.
 // Redistribution and use in source and binary forms, with or without
 // modification, are permitted provided that the following conditions are
 // met:

+ 3 - 1
Jint/Native/Number/Dtoa/DoubleHelper.cs

@@ -1,4 +1,6 @@
-// Copyright 2010 the V8 project authors. All rights reserved.
+#nullable disable
+
+// Copyright 2010 the V8 project authors. All rights reserved.
 // Redistribution and use in source and binary forms, with or without
 // modification, are permitted provided that the following conditions are
 // met:

+ 3 - 1
Jint/Native/Number/Dtoa/DtoaBuilder.cs

@@ -1,4 +1,6 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
+#nullable disable
+
+/* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 

+ 2 - 0
Jint/Native/Number/Dtoa/DtoaMode.cs

@@ -1,3 +1,5 @@
+#nullable disable
+
 namespace Jint.Native.Number.Dtoa
 {
     internal enum DtoaMode

+ 3 - 1
Jint/Native/Number/Dtoa/DtoaNumberFormatter.cs

@@ -1,4 +1,6 @@
-using System.Diagnostics;
+#nullable disable
+
+using System.Diagnostics;
 using Jint.Runtime;
 
 namespace Jint.Native.Number.Dtoa

+ 3 - 1
Jint/Native/Number/Dtoa/FastDtoa.cs

@@ -1,4 +1,6 @@
-// Copyright 2010 the V8 project authors. All rights reserved.
+#nullable disable
+
+// Copyright 2010 the V8 project authors. All rights reserved.
 // Redistribution and use in source and binary forms, with or without
 // modification, are permitted provided that the following conditions are
 // met:

+ 3 - 1
Jint/Native/Number/Dtoa/NumberExtensions.cs

@@ -1,4 +1,6 @@
-using System.Runtime.CompilerServices;
+#nullable disable
+
+using System.Runtime.CompilerServices;
 
 namespace Jint.Native.Number.Dtoa
 {

部分文件因为文件数量过多而无法显示