Quellcode durchsuchen

Replace ReferenceEquals usage with is (not) null (#1906)

Marko Lahma vor 1 Jahr
Ursprung
Commit
4110ede00b

+ 5 - 1
Jint.Tests/Runtime/ExecutionConstraintTests.cs

@@ -56,7 +56,11 @@ namespace Jint.Tests.Runtime
 
                             sleep(100);
                             waitHandle.Set();
-                            sleep(5000);
+                            sleep(1000);
+                            sleep(1000);
+                            sleep(1000);
+                            sleep(1000);
+                            sleep(1000);
                         ");
                     }
                 }

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

@@ -110,7 +110,7 @@ namespace Jint.Native.Array
                 a = ArrayCreate(length);
             }
 
-            var args = !ReferenceEquals(callable, null)
+            var args = callable is not null
                 ? _engine._jsValueArrayPool.RentArray(2)
                 : null;
 
@@ -119,7 +119,7 @@ namespace Jint.Native.Array
             for (uint i = 0; i < length; i++)
             {
                 var value = source.Get(i);
-                if (!ReferenceEquals(callable, null))
+                if (callable is not null)
                 {
                     args![0] = value;
                     args[1] = i;
@@ -133,7 +133,7 @@ namespace Jint.Native.Array
                 n++;
             }
 
-            if (!ReferenceEquals(callable, null))
+            if (callable is not null)
             {
                 _engine._jsValueArrayPool.ReturnArray(args!);
             }
@@ -165,7 +165,7 @@ namespace Jint.Native.Array
             {
                 _index++;
                 JsValue jsValue;
-                if (!ReferenceEquals(_callable, null))
+                if (_callable is not null)
                 {
                     arguments[0] = currentValue;
                     arguments[1] = _index;

+ 1 - 1
Jint/Native/Array/ArrayInstance.cs

@@ -130,7 +130,7 @@ namespace Jint.Native.Array
         private bool DefineLength(PropertyDescriptor desc)
         {
             var value = desc.Value;
-            if (ReferenceEquals(value, null))
+            if (value is null)
             {
                 return base.DefineOwnProperty(CommonProperties.Length, desc);
             }

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

@@ -178,7 +178,7 @@ namespace Jint.Native.Array
             private double GetIntegerLength()
             {
                 var descValue = _target.Get(CommonProperties.Length);
-                if (!ReferenceEquals(descValue, null))
+                if (descValue is not null)
                 {
                     return TypeConverter.ToInteger(descValue);
                 }
@@ -329,7 +329,7 @@ namespace Jint.Native.Array
                 }
 
                 var descValue = _target.Get(CommonProperties.Length);
-                if (!ReferenceEquals(descValue, null))
+                if (descValue is not null)
                 {
                     return (uint) TypeConverter.ToInteger(descValue);
                 }

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

@@ -741,7 +741,7 @@ namespace Jint.Native.Array
                     args[0] = kvalue;
                     args[1] = k;
                     var testResult = callable.Call(thisArg, args);
-                    if (false == TypeConverter.ToBoolean(testResult))
+                    if (!TypeConverter.ToBoolean(testResult))
                     {
                         return JsBoolean.False;
                     }
@@ -1695,8 +1695,8 @@ namespace Jint.Native.Array
 
             public int Compare(JsValue? x, JsValue? y)
             {
-                var xIsNull = ReferenceEquals(x, null);
-                var yIsNull = ReferenceEquals(y, null);
+                var xIsNull = x is null;
+                var yIsNull = y is null;
 
                 if (xIsNull)
                 {

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

@@ -44,7 +44,7 @@ namespace Jint.Native.Error
         public JsValue ToString(JsValue thisObject, JsValue[] arguments)
         {
             var o = thisObject.TryCast<ObjectInstance>();
-            if (ReferenceEquals(o, null))
+            if (o is null)
             {
                 ExceptionHelper.ThrowTypeError(_realm);
             }

+ 4 - 4
Jint/Native/JsArguments.cs

@@ -113,7 +113,7 @@ namespace Jint.Native
         {
             EnsureInitialized();
 
-            if (!ReferenceEquals(ParameterMap, null))
+            if (ParameterMap is not null)
             {
                 var desc = base.GetOwnProperty(property);
                 if (desc == PropertyDescriptor.Undefined)
@@ -182,7 +182,7 @@ namespace Jint.Native
 
             EnsureInitialized();
 
-            if (!ReferenceEquals(ParameterMap, null))
+            if (ParameterMap is not null)
             {
                 var map = ParameterMap;
                 var isMapped = map.GetOwnProperty(property);
@@ -201,7 +201,7 @@ namespace Jint.Native
                     else
                     {
                         var descValue = desc.Value;
-                        if (!ReferenceEquals(descValue, null) && !descValue.IsUndefined())
+                        if (descValue is not null && !descValue.IsUndefined())
                         {
                             map.Set(property, descValue, false);
                         }
@@ -223,7 +223,7 @@ namespace Jint.Native
         {
             EnsureInitialized();
 
-            if (!ReferenceEquals(ParameterMap, null))
+            if (ParameterMap is not null)
             {
                 var map = ParameterMap;
                 var isMapped = map.GetOwnProperty(property);

+ 16 - 16
Jint/Native/Object/ObjectInstance.cs

@@ -448,7 +448,7 @@ namespace Jint.Native.Object
             if (desc != PropertyDescriptor.Undefined)
             {
                 var descValue = desc.Value;
-                if (desc.WritableSet && !ReferenceEquals(descValue, null))
+                if (desc.WritableSet && descValue is not null)
                 {
                     value = descValue;
                     return true;
@@ -600,7 +600,7 @@ namespace Jint.Native.Object
                 if (desc.IsAccessorDescriptor())
                 {
                     var set = desc.Set;
-                    if (ReferenceEquals(set, null) || set.IsUndefined())
+                    if (set is null || set.IsUndefined())
                     {
                         return false;
                     }
@@ -611,7 +611,7 @@ namespace Jint.Native.Object
                 return desc.Writable;
             }
 
-            if (ReferenceEquals(Prototype, null))
+            if (Prototype is null)
             {
                 return Extensible;
             }
@@ -626,7 +626,7 @@ namespace Jint.Native.Object
             if (inherited.IsAccessorDescriptor())
             {
                 var set = inherited.Set;
-                if (ReferenceEquals(set, null) || set.IsUndefined())
+                if (set is null || set.IsUndefined())
                 {
                     return false;
                 }
@@ -781,9 +781,9 @@ namespace Jint.Native.Object
 
             // 4. If every field in Desc is absent, return true.
             if ((current._flags & (PropertyFlag.ConfigurableSet | PropertyFlag.EnumerableSet | PropertyFlag.WritableSet)) == PropertyFlag.None &&
-                ReferenceEquals(currentGet, null) &&
-                ReferenceEquals(currentSet, null) &&
-                ReferenceEquals(currentValue, null))
+                currentGet is null &&
+                currentSet is null &&
+                currentValue is null)
             {
                 return true;
             }
@@ -795,9 +795,9 @@ namespace Jint.Native.Object
                 current.Configurable == desc.Configurable && current.ConfigurableSet == desc.ConfigurableSet &&
                 current.Writable == desc.Writable && current.WritableSet == desc.WritableSet &&
                 current.Enumerable == desc.Enumerable && current.EnumerableSet == desc.EnumerableSet &&
-                ((ReferenceEquals(currentGet, null) && ReferenceEquals(descGet, null)) || (!ReferenceEquals(currentGet, null) && !ReferenceEquals(descGet, null) && SameValue(currentGet, descGet))) &&
-                ((ReferenceEquals(currentSet, null) && ReferenceEquals(descSet, null)) || (!ReferenceEquals(currentSet, null) && !ReferenceEquals(descSet, null) && SameValue(currentSet, descSet))) &&
-                ((ReferenceEquals(currentValue, null) && ReferenceEquals(descValue, null)) || (!ReferenceEquals(currentValue, null) && !ReferenceEquals(descValue, null) && currentValue == descValue))
+                ((currentGet is null && descGet is null) || (currentGet is not null && descGet is not null && SameValue(currentGet, descGet))) &&
+                ((currentSet is null && descSet is null) || (currentSet is not null && descSet is not null && SameValue(currentSet, descSet))) &&
+                ((currentValue is null && descValue is null) || (currentValue is not null && descValue is not null && currentValue == descValue))
             )
             {
                 return true;
@@ -856,7 +856,7 @@ namespace Jint.Native.Object
 
                         if (!current.Writable)
                         {
-                            if (!ReferenceEquals(descValue, null) && !SameValue(descValue, currentValue!))
+                            if (descValue is not null && !SameValue(descValue, currentValue!))
                             {
                                 return false;
                             }
@@ -867,9 +867,9 @@ namespace Jint.Native.Object
                 {
                     if (!current.Configurable)
                     {
-                        if ((!ReferenceEquals(descSet, null) && !SameValue(descSet, currentSet ?? Undefined))
+                        if ((descSet is not null && !SameValue(descSet, currentSet ?? Undefined))
                             ||
-                            (!ReferenceEquals(descGet, null) && !SameValue(descGet, currentGet ?? Undefined)))
+                            (descGet is not null && !SameValue(descGet, currentGet ?? Undefined)))
                         {
                             return false;
                         }
@@ -879,7 +879,7 @@ namespace Jint.Native.Object
 
             if (o is not null)
             {
-                if (!ReferenceEquals(descValue, null))
+                if (descValue is not null)
                 {
                     current.Value = descValue;
                 }
@@ -900,13 +900,13 @@ namespace Jint.Native.Object
                 }
 
                 PropertyDescriptor? mutable = null;
-                if (!ReferenceEquals(descGet, null))
+                if (descGet is not null)
                 {
                     mutable = new GetSetPropertyDescriptor(mutable ?? current);
                     ((GetSetPropertyDescriptor) mutable).SetGet(descGet);
                 }
 
-                if (!ReferenceEquals(descSet, null))
+                if (descSet is not null)
                 {
                     mutable = new GetSetPropertyDescriptor(mutable ?? current);
                     ((GetSetPropertyDescriptor) mutable).SetSet(descSet);

+ 1 - 1
Jint/Native/Object/ObjectPrototype.cs

@@ -220,7 +220,7 @@ namespace Jint.Native.Object
             {
                 v = v.Prototype;
 
-                if (ReferenceEquals(v, null))
+                if (v is null)
                 {
                     return JsBoolean.False;
                 }

+ 1 - 1
Jint/Native/String/StringPrototype.cs

@@ -113,7 +113,7 @@ namespace Jint.Native.String
             }
 
             var s = TypeConverter.ToObject(_realm, thisObject) as StringInstance;
-            if (ReferenceEquals(s, null))
+            if (s is null)
             {
                 ExceptionHelper.ThrowTypeError(_realm);
             }

+ 1 - 1
Jint/Pooling/ArgumentsInstancePool.cs

@@ -43,7 +43,7 @@ namespace Jint.Pooling
 
         public void Return(JsArguments instance)
         {
-            if (ReferenceEquals(instance, null))
+            if (instance is null)
             {
                 return;
             }

+ 4 - 4
Jint/Pooling/ObjectPool.cs

@@ -136,7 +136,7 @@ namespace Jint.Pooling
             // We will interlock only when we have a candidate. in a worst case we may miss some
             // recently returned objects. Not a big deal.
             T inst = _firstItem;
-            if (!ReferenceEquals(inst, null))
+            if (inst is not null)
             {
                 _firstItem = null;
                 return inst;
@@ -163,7 +163,7 @@ namespace Jint.Pooling
             for (int i = 0; i < items.Length; i++)
             {
                 T inst = items[i].Value;
-                if (!ReferenceEquals(inst, null))
+                if (inst is not null)
                 {
                     items[i].Value = null;
                     return inst;
@@ -186,7 +186,7 @@ namespace Jint.Pooling
             Validate(obj);
             ForgetTrackedObject(obj);
 
-            if (ReferenceEquals(_firstItem, null))
+            if (_firstItem is null)
             {
                 // Intentionally not using interlocked here.
                 // In a worst case scenario two objects may be stored into same slot.
@@ -267,7 +267,7 @@ namespace Jint.Pooling
             for (int i = 0; i < items.Length; i++)
             {
                 var value = items[i].Value;
-                if (ReferenceEquals(value, null))
+                if (value is null)
                 {
                     return;
                 }

+ 3 - 3
Jint/Runtime/Descriptors/PropertyDescriptor.cs

@@ -390,7 +390,7 @@ namespace Jint.Runtime.Descriptors
         [MethodImpl(MethodImplOptions.AggressiveInlining)]
         public bool IsAccessorDescriptor()
         {
-            return !ReferenceEquals(Get, null) || !ReferenceEquals(Set, null);
+            return Get is not null || Set is not null;
         }
 
         [MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -401,8 +401,8 @@ namespace Jint.Runtime.Descriptors
                 return false;
             }
             return (_flags & (PropertyFlag.WritableSet | PropertyFlag.Writable)) != PropertyFlag.None
-                   || (_flags & PropertyFlag.CustomJsValue) != PropertyFlag.None && !ReferenceEquals(CustomValue, null)
-                   || !ReferenceEquals(_value, null);
+                   || (_flags & PropertyFlag.CustomJsValue) != PropertyFlag.None && CustomValue is not null
+                   || _value is not null;
         }
 
         /// <summary>

+ 2 - 2
Jint/Runtime/Environments/JintEnvironment.cs

@@ -19,7 +19,7 @@ namespace Jint.Runtime.Environments
                 return env.HasBinding(name);
             }
 
-            while (!ReferenceEquals(record, null))
+            while (record is not null)
             {
                 if (record.HasBinding(name))
                 {
@@ -46,7 +46,7 @@ namespace Jint.Runtime.Environments
                 return ((GlobalEnvironment) env).TryGetBinding(name, out value);
             }
 
-            while (!ReferenceEquals(record, null))
+            while (record is not null)
             {
                 if (record.TryGetBinding(name, out value))
                 {

+ 1 - 1
Jint/Runtime/Environments/ObjectEnvironment.cs

@@ -167,7 +167,7 @@ namespace Jint.Runtime.Environments
 
         internal override string[] GetAllBindingNames()
         {
-            if (!ReferenceEquals(_bindingObject, null))
+            if (_bindingObject is not null)
             {
                 var names = new List<string>(_bindingObject._properties?.Count ?? 0);
                 foreach (var name in _bindingObject.GetOwnProperties())

+ 1 - 1
Jint/Runtime/Interop/NamespaceReference.cs

@@ -55,7 +55,7 @@ namespace Jint.Runtime.Interop
 
             var typeReference = GetPath(_path + "`" + arguments.Length.ToString(CultureInfo.InvariantCulture)).As<TypeReference>();
 
-            if (ReferenceEquals(typeReference, null))
+            if (typeReference is null)
             {
                 return Undefined;
             }