Przeglądaj źródła

Remove Enum.HasFlag usage (#1850)

* cleanup Array capacity usage
Marko Lahma 1 rok temu
rodzic
commit
dadeb15519

+ 0 - 1
Jint/Native/Array/ArrayOperations.cs

@@ -629,7 +629,6 @@ namespace Jint.Native.Array
 
             public override void Set(ulong index, JsValue value, bool updateLength = false, bool throwOnError = true)
             {
-                EnsureCapacity(index + 1);
                 _target.SetAt((int)index, value);
             }
 

+ 6 - 1
Jint/Native/Array/ArrayPrototype.cs

@@ -1019,7 +1019,12 @@ namespace Jint.Native.Array
                 ExceptionHelper.ThrowTypeError(_realm, "Invalid array length");
             }
 
-            o.EnsureCapacity(len + argCount);
+            // only prepare for larger if we cannot rely on default growth algorithm
+            if (len + argCount > 2 * len)
+            {
+                o.EnsureCapacity(len + argCount);
+            }
+
             var minIndex = o.GetSmallestIndex(len);
             for (var k = len; k > minIndex; k--)
             {

+ 1 - 36
Jint/Runtime/Descriptors/PropertyDescriptor.cs

@@ -396,7 +396,7 @@ namespace Jint.Runtime.Descriptors
         [MethodImpl(MethodImplOptions.AggressiveInlining)]
         public bool IsDataDescriptor()
         {
-            if (_flags.HasFlag(PropertyFlag.NonData))
+            if ((_flags & PropertyFlag.NonData) != PropertyFlag.None)
             {
                 return false;
             }
@@ -415,41 +415,6 @@ namespace Jint.Runtime.Descriptors
             return !IsDataDescriptor() && !IsAccessorDescriptor();
         }
 
-        [MethodImpl(MethodImplOptions.AggressiveInlining)]
-        internal bool TryGetValue(ObjectInstance thisArg, out JsValue value)
-        {
-            value = JsValue.Undefined;
-
-            // IsDataDescriptor logic inlined
-            if ((_flags & (PropertyFlag.WritableSet | PropertyFlag.Writable)) != PropertyFlag.None)
-            {
-                var val = (_flags & PropertyFlag.CustomJsValue) != PropertyFlag.None
-                    ? CustomValue
-                    : _value;
-
-                if (!ReferenceEquals(val, null))
-                {
-                    value = val;
-                    return true;
-                }
-            }
-
-            if (this == Undefined)
-            {
-                return false;
-            }
-
-            var getter = Get;
-            if (!ReferenceEquals(getter, null) && !getter.IsUndefined())
-            {
-                // if getter is not undefined it must be ICallable
-                var callable = (ICallable) getter;
-                value = callable.Call(thisArg, Arguments.Empty);
-            }
-
-            return true;
-        }
-
         private sealed class UndefinedPropertyDescriptor : PropertyDescriptor
         {
             public UndefinedPropertyDescriptor() : base(PropertyFlag.None | PropertyFlag.CustomJsValue)

+ 1 - 1
Jint/Runtime/Interop/ObjectWrapper.Specialized.cs

@@ -81,7 +81,7 @@ internal abstract class ArrayLikeWrapper : ObjectWrapper
     {
         if (_engine.Options.Interop.AllowWrite)
         {
-            EnsureCapacity(index);
+            EnsureCapacity(index + 1);
             DoSetAt(index, ConvertToItemType(value));
         }
     }

+ 1 - 1
Jint/Runtime/Interop/Reflection/FieldAccessor.cs

@@ -12,7 +12,7 @@ internal sealed class FieldAccessor : ReflectionAccessor
         _fieldInfo = fieldInfo;
     }
 
-    public override bool Writable => !_fieldInfo.Attributes.HasFlag(FieldAttributes.InitOnly);
+    public override bool Writable => (_fieldInfo.Attributes & FieldAttributes.InitOnly) == (FieldAttributes) 0;
 
     protected override object? DoGetValue(object target, string memberName)
     {

+ 1 - 1
Jint/Runtime/Interpreter/Expressions/JintYieldExpression.cs

@@ -13,7 +13,7 @@ internal sealed class JintYieldExpression : JintExpression
 
     protected override object EvaluateInternal(EvaluationContext context)
     {
-        if (!context.Engine.Options.ExperimentalFeatures.HasFlag(ExperimentalFeature.Generators))
+        if ((context.Engine.Options.ExperimentalFeatures & ExperimentalFeature.Generators) == ExperimentalFeature.None)
         {
             ExceptionHelper.ThrowJavaScriptException(
                 context.Engine.Intrinsics.Error,