diff --git a/Jint.Tests/Runtime/ExecutionConstraintTests.cs b/Jint.Tests/Runtime/ExecutionConstraintTests.cs index 76d1516ffc..ca2315ba9d 100644 --- a/Jint.Tests/Runtime/ExecutionConstraintTests.cs +++ b/Jint.Tests/Runtime/ExecutionConstraintTests.cs @@ -56,7 +56,11 @@ function sleep(millisecondsTimeout) { sleep(100); waitHandle.Set(); - sleep(5000); + sleep(1000); + sleep(1000); + sleep(1000); + sleep(1000); + sleep(1000); "); } } diff --git a/Jint/Native/Array/ArrayConstructor.cs b/Jint/Native/Array/ArrayConstructor.cs index 6e83b56e88..b8f0278b12 100644 --- a/Jint/Native/Array/ArrayConstructor.cs +++ b/Jint/Native/Array/ArrayConstructor.cs @@ -110,7 +110,7 @@ private ObjectInstance ConstructArrayFromArrayLike( a = ArrayCreate(length); } - var args = !ReferenceEquals(callable, null) + var args = callable is not null ? _engine._jsValueArrayPool.RentArray(2) : null; @@ -119,7 +119,7 @@ private ObjectInstance ConstructArrayFromArrayLike( 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 @@ private ObjectInstance ConstructArrayFromArrayLike( n++; } - if (!ReferenceEquals(callable, null)) + if (callable is not null) { _engine._jsValueArrayPool.ReturnArray(args!); } @@ -165,7 +165,7 @@ protected override void ProcessItem(JsValue[] arguments, JsValue currentValue) { _index++; JsValue jsValue; - if (!ReferenceEquals(_callable, null)) + if (_callable is not null) { arguments[0] = currentValue; arguments[1] = _index; diff --git a/Jint/Native/Array/ArrayInstance.cs b/Jint/Native/Array/ArrayInstance.cs index 9183a45f0a..e7e676df55 100644 --- a/Jint/Native/Array/ArrayInstance.cs +++ b/Jint/Native/Array/ArrayInstance.cs @@ -130,7 +130,7 @@ public sealed override bool DefineOwnProperty(JsValue property, PropertyDescript private bool DefineLength(PropertyDescriptor desc) { var value = desc.Value; - if (ReferenceEquals(value, null)) + if (value is null) { return base.DefineOwnProperty(CommonProperties.Length, desc); } diff --git a/Jint/Native/Array/ArrayOperations.cs b/Jint/Native/Array/ArrayOperations.cs index 1db3e8bf59..3ba1b68091 100644 --- a/Jint/Native/Array/ArrayOperations.cs +++ b/Jint/Native/Array/ArrayOperations.cs @@ -178,7 +178,7 @@ public ObjectOperations(ObjectInstance target) : base(target) 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 @@ public override uint GetLength() } var descValue = _target.Get(CommonProperties.Length); - if (!ReferenceEquals(descValue, null)) + if (descValue is not null) { return (uint) TypeConverter.ToInteger(descValue); } diff --git a/Jint/Native/Array/ArrayPrototype.cs b/Jint/Native/Array/ArrayPrototype.cs index bb7331858b..7b7d711594 100644 --- a/Jint/Native/Array/ArrayPrototype.cs +++ b/Jint/Native/Array/ArrayPrototype.cs @@ -741,7 +741,7 @@ private JsValue Every(JsValue thisObject, JsValue[] arguments) 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 @@ private ArrayComparer(Engine? engine, ICallable? compare) 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) { diff --git a/Jint/Native/Error/ErrorPrototype.cs b/Jint/Native/Error/ErrorPrototype.cs index 87853babcd..9d546863b0 100644 --- a/Jint/Native/Error/ErrorPrototype.cs +++ b/Jint/Native/Error/ErrorPrototype.cs @@ -44,7 +44,7 @@ protected override void Initialize() public JsValue ToString(JsValue thisObject, JsValue[] arguments) { var o = thisObject.TryCast(); - if (ReferenceEquals(o, null)) + if (o is null) { ExceptionHelper.ThrowTypeError(_realm); } diff --git a/Jint/Native/JsArguments.cs b/Jint/Native/JsArguments.cs index d0f7514e80..3e53ec42cd 100644 --- a/Jint/Native/JsArguments.cs +++ b/Jint/Native/JsArguments.cs @@ -113,7 +113,7 @@ public override PropertyDescriptor GetOwnProperty(JsValue property) { EnsureInitialized(); - if (!ReferenceEquals(ParameterMap, null)) + if (ParameterMap is not null) { var desc = base.GetOwnProperty(property); if (desc == PropertyDescriptor.Undefined) @@ -182,7 +182,7 @@ public override bool DefineOwnProperty(JsValue property, PropertyDescriptor desc EnsureInitialized(); - if (!ReferenceEquals(ParameterMap, null)) + if (ParameterMap is not null) { var map = ParameterMap; var isMapped = map.GetOwnProperty(property); @@ -201,7 +201,7 @@ public override bool DefineOwnProperty(JsValue property, PropertyDescriptor desc 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 @@ public override bool Delete(JsValue property) { EnsureInitialized(); - if (!ReferenceEquals(ParameterMap, null)) + if (ParameterMap is not null) { var map = ParameterMap; var isMapped = map.GetOwnProperty(property); diff --git a/Jint/Native/Object/ObjectInstance.cs b/Jint/Native/Object/ObjectInstance.cs index ad3e2a22c9..7a49003898 100644 --- a/Jint/Native/Object/ObjectInstance.cs +++ b/Jint/Native/Object/ObjectInstance.cs @@ -448,7 +448,7 @@ public bool TryGetValue(JsValue property, out JsValue value) 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 @@ internal bool CanPut(JsValue property) 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 @@ internal bool CanPut(JsValue property) return desc.Writable; } - if (ReferenceEquals(Prototype, null)) + if (Prototype is null) { return Extensible; } @@ -626,7 +626,7 @@ internal bool CanPut(JsValue property) 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 @@ protected static bool ValidateAndApplyPropertyDescriptor(ObjectInstance? o, JsVa // 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 @@ protected static bool ValidateAndApplyPropertyDescriptor(ObjectInstance? o, JsVa 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 @@ protected static bool ValidateAndApplyPropertyDescriptor(ObjectInstance? o, JsVa if (!current.Writable) { - if (!ReferenceEquals(descValue, null) && !SameValue(descValue, currentValue!)) + if (descValue is not null && !SameValue(descValue, currentValue!)) { return false; } @@ -867,9 +867,9 @@ protected static bool ValidateAndApplyPropertyDescriptor(ObjectInstance? o, JsVa { 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 @@ protected static bool ValidateAndApplyPropertyDescriptor(ObjectInstance? o, JsVa if (o is not null) { - if (!ReferenceEquals(descValue, null)) + if (descValue is not null) { current.Value = descValue; } @@ -900,13 +900,13 @@ protected static bool ValidateAndApplyPropertyDescriptor(ObjectInstance? o, JsVa } 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); diff --git a/Jint/Native/Object/ObjectPrototype.cs b/Jint/Native/Object/ObjectPrototype.cs index df34f02664..9122f4ae87 100644 --- a/Jint/Native/Object/ObjectPrototype.cs +++ b/Jint/Native/Object/ObjectPrototype.cs @@ -220,7 +220,7 @@ private JsValue IsPrototypeOf(JsValue thisObject, JsValue[] arguments) { v = v.Prototype; - if (ReferenceEquals(v, null)) + if (v is null) { return JsBoolean.False; } diff --git a/Jint/Native/String/StringPrototype.cs b/Jint/Native/String/StringPrototype.cs index d969e3efe5..10669995fe 100644 --- a/Jint/Native/String/StringPrototype.cs +++ b/Jint/Native/String/StringPrototype.cs @@ -113,7 +113,7 @@ private JsValue ToStringString(JsValue thisObject, JsValue[] arguments) } var s = TypeConverter.ToObject(_realm, thisObject) as StringInstance; - if (ReferenceEquals(s, null)) + if (s is null) { ExceptionHelper.ThrowTypeError(_realm); } diff --git a/Jint/Pooling/ArgumentsInstancePool.cs b/Jint/Pooling/ArgumentsInstancePool.cs index c33fe66663..9fe0ac987a 100644 --- a/Jint/Pooling/ArgumentsInstancePool.cs +++ b/Jint/Pooling/ArgumentsInstancePool.cs @@ -43,7 +43,7 @@ public JsArguments Rent( public void Return(JsArguments instance) { - if (ReferenceEquals(instance, null)) + if (instance is null) { return; } diff --git a/Jint/Pooling/ObjectPool.cs b/Jint/Pooling/ObjectPool.cs index 050c43b63e..ec0ee96033 100644 --- a/Jint/Pooling/ObjectPool.cs +++ b/Jint/Pooling/ObjectPool.cs @@ -136,7 +136,7 @@ internal T Allocate() // 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 @@ private T AllocateSlow() 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 @@ internal void Free(T obj) 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 @@ private void Validate(object obj) for (int i = 0; i < items.Length; i++) { var value = items[i].Value; - if (ReferenceEquals(value, null)) + if (value is null) { return; } diff --git a/Jint/Runtime/Descriptors/PropertyDescriptor.cs b/Jint/Runtime/Descriptors/PropertyDescriptor.cs index 77cab8d9da..62c6e25ea6 100644 --- a/Jint/Runtime/Descriptors/PropertyDescriptor.cs +++ b/Jint/Runtime/Descriptors/PropertyDescriptor.cs @@ -390,7 +390,7 @@ public static JsValue FromPropertyDescriptor(Engine engine, PropertyDescriptor d [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 @@ public bool IsDataDescriptor() 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; } /// diff --git a/Jint/Runtime/Environments/JintEnvironment.cs b/Jint/Runtime/Environments/JintEnvironment.cs index 80aa73f9a0..74b27a00e1 100644 --- a/Jint/Runtime/Environments/JintEnvironment.cs +++ b/Jint/Runtime/Environments/JintEnvironment.cs @@ -19,7 +19,7 @@ record = env; return env.HasBinding(name); } - while (!ReferenceEquals(record, null)) + while (record is not null) { if (record.HasBinding(name)) { @@ -46,7 +46,7 @@ record = env; return ((GlobalEnvironment) env).TryGetBinding(name, out value); } - while (!ReferenceEquals(record, null)) + while (record is not null) { if (record.TryGetBinding(name, out value)) { diff --git a/Jint/Runtime/Environments/ObjectEnvironment.cs b/Jint/Runtime/Environments/ObjectEnvironment.cs index 46df2860e5..c6b33e6422 100644 --- a/Jint/Runtime/Environments/ObjectEnvironment.cs +++ b/Jint/Runtime/Environments/ObjectEnvironment.cs @@ -167,7 +167,7 @@ internal override JsValue GetBindingValue(Key name, bool strict) internal override string[] GetAllBindingNames() { - if (!ReferenceEquals(_bindingObject, null)) + if (_bindingObject is not null) { var names = new List(_bindingObject._properties?.Count ?? 0); foreach (var name in _bindingObject.GetOwnProperties()) diff --git a/Jint/Runtime/Interop/NamespaceReference.cs b/Jint/Runtime/Interop/NamespaceReference.cs index c14c898bc8..2bd674c03a 100644 --- a/Jint/Runtime/Interop/NamespaceReference.cs +++ b/Jint/Runtime/Interop/NamespaceReference.cs @@ -55,7 +55,7 @@ JsValue ICallable.Call(JsValue thisObject, JsValue[] arguments) var typeReference = GetPath(_path + "`" + arguments.Length.ToString(CultureInfo.InvariantCulture)).As(); - if (ReferenceEquals(typeReference, null)) + if (typeReference is null) { return Undefined; }