Browse Source

Update test262 test suite and fix issues (#1944)

Marko Lahma 11 months ago
parent
commit
d29244cdb6

+ 1 - 1
Jint.Tests.Test262/Test262Harness.settings.json

@@ -1,5 +1,5 @@
 {
 {
-  "SuiteGitSha": "5dc04b733275cf64e3022867359e27bc99d9262c",
+  "SuiteGitSha": "941813e1f0e64ae9a5c4c5c8075f49ff89b0c642",
   //"SuiteDirectory": "//mnt/c/work/test262",
   //"SuiteDirectory": "//mnt/c/work/test262",
   "TargetPath": "./Generated",
   "TargetPath": "./Generated",
   "Namespace": "Jint.Tests.Test262",
   "Namespace": "Jint.Tests.Test262",

+ 13 - 20
Jint/Native/Array/ArrayPrototype.cs

@@ -1300,42 +1300,35 @@ public sealed class ArrayPrototype : ArrayInstance
         return sb.ToString();
         return sb.ToString();
     }
     }
 
 
+    /// <summary>
+    /// https://tc39.es/ecma262/#sec-array.prototype.tolocalestring
+    /// </summary>
     private JsValue ToLocaleString(JsValue thisObject, JsValue[] arguments)
     private JsValue ToLocaleString(JsValue thisObject, JsValue[] arguments)
     {
     {
+        const string Separator = ",";
+
         var array = ArrayOperations.For(_realm, thisObject, forWrite: false);
         var array = ArrayOperations.For(_realm, thisObject, forWrite: false);
         var len = array.GetLength();
         var len = array.GetLength();
-        const string Separator = ",";
         if (len == 0)
         if (len == 0)
         {
         {
             return JsString.Empty;
             return JsString.Empty;
         }
         }
 
 
-        JsValue r;
-        if (!array.TryGetValue(0, out var firstElement) || firstElement.IsNull() || firstElement.IsUndefined())
-        {
-            r = JsString.Empty;
-        }
-        else
-        {
-            r = Invoke(firstElement, "toLocaleString", System.Array.Empty<JsValue>());
-        }
-
-        for (uint k = 1; k < len; k++)
+        using var r = new ValueStringBuilder();
+        for (uint k = 0; k < len; k++)
         {
         {
-            var s = r + Separator;
-            if (!array.TryGetValue(k, out var nextElement) || nextElement.IsNull())
+            if (k > 0)
             {
             {
-                r = JsString.Empty;
+                r.Append(Separator);
             }
             }
-            else
+            if (array.TryGetValue(k, out var nextElement) && !nextElement.IsNullOrUndefined())
             {
             {
-                r = Invoke(nextElement, "toLocaleString", System.Array.Empty<JsValue>());
+                var s = TypeConverter.ToString(Invoke(nextElement, "toLocaleString", []));
+                r.Append(s);
             }
             }
-
-            r = s + r;
         }
         }
 
 
-        return r;
+        return r.ToString();
     }
     }
 
 
     /// <summary>
     /// <summary>

+ 10 - 2
Jint/Native/JsTypedArray.cs

@@ -142,8 +142,16 @@ public sealed class JsTypedArray : ObjectInstance
         var numericIndex = TypeConverter.CanonicalNumericIndexString(property);
         var numericIndex = TypeConverter.CanonicalNumericIndexString(property);
         if (numericIndex is not null)
         if (numericIndex is not null)
         {
         {
-            IntegerIndexedElementSet(numericIndex.Value, value);
-            return true;
+            if (ReferenceEquals(this, receiver))
+            {
+                IntegerIndexedElementSet(numericIndex.Value, value);
+                return true;
+            }
+
+            if (!IsValidIntegerIndex(numericIndex.Value))
+            {
+                return true;
+            }
         }
         }
 
 
         return base.Set(property, value, receiver);
         return base.Set(property, value, receiver);

+ 4 - 1
Jint/Native/Number/NumberPrototype.cs

@@ -48,9 +48,12 @@ internal sealed class NumberPrototype : NumberInstance
         SetProperties(properties);
         SetProperties(properties);
     }
     }
 
 
+    /// <summary>
+    /// https://tc39.es/ecma262/#sec-number.prototype.tolocalestring
+    /// </summary>
     private JsValue ToLocaleString(JsValue thisObject, JsValue[] arguments)
     private JsValue ToLocaleString(JsValue thisObject, JsValue[] arguments)
     {
     {
-        if (!thisObject.IsNumber() && ReferenceEquals(thisObject.TryCast<NumberInstance>(), null))
+        if (!thisObject.IsNumber() && thisObject is not NumberInstance)
         {
         {
             ExceptionHelper.ThrowTypeError(_realm);
             ExceptionHelper.ThrowTypeError(_realm);
         }
         }

+ 34 - 44
Jint/Native/TypedArray/IntrinsicTypedArrayPrototype.cs

@@ -1198,54 +1198,61 @@ internal sealed class IntrinsicTypedArrayPrototype : Prototype
         var len = taRecord.TypedArrayLength;
         var len = taRecord.TypedArrayLength;
 
 
         var relativeStart = TypeConverter.ToIntegerOrInfinity(start);
         var relativeStart = TypeConverter.ToIntegerOrInfinity(start);
-        int k;
+        int startIndex;
         if (double.IsNegativeInfinity(relativeStart))
         if (double.IsNegativeInfinity(relativeStart))
         {
         {
-            k = 0;
+            startIndex = 0;
         }
         }
         else if (relativeStart < 0)
         else if (relativeStart < 0)
         {
         {
-            k = (int) System.Math.Max(len + relativeStart, 0);
+            startIndex = (int) System.Math.Max(len + relativeStart, 0);
         }
         }
         else
         else
         {
         {
-            k = (int) System.Math.Min(relativeStart, len);
+            startIndex = (int) System.Math.Min(relativeStart, len);
         }
         }
 
 
         var relativeEnd = end.IsUndefined()
         var relativeEnd = end.IsUndefined()
             ? len
             ? len
             : TypeConverter.ToIntegerOrInfinity(end);
             : TypeConverter.ToIntegerOrInfinity(end);
 
 
-        long final;
+        long endIndex;
         if (double.IsNegativeInfinity(relativeEnd))
         if (double.IsNegativeInfinity(relativeEnd))
         {
         {
-            final = 0;
+            endIndex = 0;
         }
         }
         else if (relativeEnd < 0)
         else if (relativeEnd < 0)
         {
         {
-            final = (long) System.Math.Max(len + relativeEnd, 0);
+            endIndex = (long) System.Math.Max(len + relativeEnd, 0);
         }
         }
         else
         else
         {
         {
-            final = (long) System.Math.Min(relativeEnd, len);
+            endIndex = (long) System.Math.Min(relativeEnd, len);
         }
         }
 
 
-        var count = System.Math.Max(final - k, 0);
-        var a = _realm.Intrinsics.TypedArray.TypedArraySpeciesCreate(o, new JsValue[] { count });
+        var countBytes = System.Math.Max(endIndex - startIndex, 0);
+        var a = _realm.Intrinsics.TypedArray.TypedArraySpeciesCreate(o, new JsValue[] { countBytes });
 
 
-        if (count > 0)
+        if (countBytes > 0)
         {
         {
-            o._viewedArrayBuffer.AssertNotDetached();
+            taRecord = MakeTypedArrayWithBufferWitnessRecord(o, ArrayBufferOrder.SeqCst);
+            if (taRecord.IsTypedArrayOutOfBounds)
+            {
+                ExceptionHelper.ThrowTypeError(_realm, "TypedArray is out of bounds");
+            }
+
+            endIndex = System.Math.Min(endIndex, taRecord.TypedArrayLength);
+            countBytes = System.Math.Max(endIndex - startIndex, 0);
             var srcType = o._arrayElementType;
             var srcType = o._arrayElementType;
             var targetType = a._arrayElementType;
             var targetType = a._arrayElementType;
             if (srcType != targetType)
             if (srcType != targetType)
             {
             {
                 var n = 0;
                 var n = 0;
-                while (k < final)
+                while (startIndex < endIndex)
                 {
                 {
-                    var kValue = o[k];
+                    var kValue = o[startIndex];
                     a[n] = kValue;
                     a[n] = kValue;
-                    k++;
+                    startIndex++;
                     n++;
                     n++;
                 }
                 }
             }
             }
@@ -1256,8 +1263,8 @@ internal sealed class IntrinsicTypedArrayPrototype : Prototype
                 var elementSize = srcType.GetElementSize();
                 var elementSize = srcType.GetElementSize();
                 var srcByteOffset = o._byteOffset;
                 var srcByteOffset = o._byteOffset;
                 var targetByteIndex = a._byteOffset;
                 var targetByteIndex = a._byteOffset;
-                var srcByteIndex = (int) k * elementSize + srcByteOffset;
-                var limit = targetByteIndex + count * elementSize;
+                var srcByteIndex = (int) startIndex * elementSize + srcByteOffset;
+                var limit = targetByteIndex + countBytes * elementSize;
                 while (targetByteIndex < limit)
                 while (targetByteIndex < limit)
                 {
                 {
                     var value = srcBuffer.GetValueFromBuffer(srcByteIndex, TypedArrayElementType.Uint8, true, ArrayBufferOrder.Unordered);
                     var value = srcBuffer.GetValueFromBuffer(srcByteIndex, TypedArrayElementType.Uint8, true, ArrayBufferOrder.Unordered);
@@ -1428,49 +1435,32 @@ internal sealed class IntrinsicTypedArrayPrototype : Prototype
          * any observable changes in the specified behaviour of the algorithm.
          * any observable changes in the specified behaviour of the algorithm.
          */
          */
 
 
+        const string Separator = ",";
+
         var taRecord = thisObject.ValidateTypedArray(_realm, ArrayBufferOrder.SeqCst);
         var taRecord = thisObject.ValidateTypedArray(_realm, ArrayBufferOrder.SeqCst);
         var array = taRecord.Object;
         var array = taRecord.Object;
         var len = taRecord.TypedArrayLength;
         var len = taRecord.TypedArrayLength;
 
 
-        const string separator = ",";
         if (len == 0)
         if (len == 0)
         {
         {
             return JsString.Empty;
             return JsString.Empty;
         }
         }
 
 
-        JsValue r;
-        if (!array.TryGetValue(0, out var firstElement) || firstElement.IsNull() || firstElement.IsUndefined())
-        {
-            r = JsString.Empty;
-        }
-        else
+        using var r = new ValueStringBuilder();
+        for (uint k = 0; k < len; k++)
         {
         {
-            var elementObj = TypeConverter.ToObject(_realm, firstElement);
-            var func = elementObj.Get("toLocaleString") as ICallable;
-            if (func is null)
+            if (k > 0)
             {
             {
-                ExceptionHelper.ThrowTypeError(_realm);
+                r.Append(Separator);
             }
             }
-
-            r = func.Call(elementObj, Arguments.Empty);
-        }
-
-        for (var k = 1; k < len; k++)
-        {
-            var s = r + separator;
-            var elementObj = TypeConverter.ToObject(_realm, array[k]);
-            var func = elementObj.Get("toLocaleString") as ICallable;
-            if (func is null)
+            if (array.TryGetValue(k, out var nextElement) && !nextElement.IsNullOrUndefined())
             {
             {
-                ExceptionHelper.ThrowTypeError(_realm);
+                var s = TypeConverter.ToString(Invoke(nextElement, "toLocaleString", []));
+                r.Append(s);
             }
             }
-
-            r = func.Call(elementObj, Arguments.Empty);
-
-            r = s + r;
         }
         }
 
 
-        return r;
+        return r.ToString();
     }
     }
 
 
     /// <summary>
     /// <summary>