Browse Source

Rename ArrayBufferInstance to JsArrayBuffer and make it public (#1591)

Marko Lahma 2 years ago
parent
commit
2ce1349039

+ 1 - 1
Jint.Tests.Test262/Test262Test.cs

@@ -56,7 +56,7 @@ public abstract partial class Test262Test
         o.FastSetProperty("detachArrayBuffer", new PropertyDescriptor(new ClrFunctionInstance(engine, "detachArrayBuffer",
             (_, args) =>
             {
-                var buffer = (ArrayBufferInstance) args.At(0);
+                var buffer = (JsArrayBuffer) args.At(0);
                 buffer.DetachArrayBuffer();
                 return JsValue.Undefined;
             }), true, true, true));

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

@@ -76,12 +76,12 @@ namespace Jint.Native.ArrayBuffer
             return AllocateArrayBuffer(newTarget, byteLength);
         }
 
-        internal ArrayBufferInstance AllocateArrayBuffer(JsValue constructor, ulong byteLength)
+        internal JsArrayBuffer AllocateArrayBuffer(JsValue constructor, ulong byteLength)
         {
             var obj = OrdinaryCreateFromConstructor(
                 constructor,
                 static intrinsics => intrinsics.ArrayBuffer.PrototypeObject,
-                static (engine, realm, state) => new ArrayBufferInstance(engine, (ulong) state!._value),
+                static (engine, realm, state) => new JsArrayBuffer(engine, (ulong) state!._value),
                 JsNumber.Create(byteLength));
 
             return obj;

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

@@ -44,7 +44,7 @@ namespace Jint.Native.ArrayBuffer
 
         private JsValue Detached(JsValue thisObj, JsValue[] arguments)
         {
-            var o = thisObj as ArrayBufferInstance;
+            var o = thisObj as JsArrayBuffer;
             if (o is null)
             {
                 ExceptionHelper.ThrowTypeError(_realm, "Method ArrayBuffer.prototype.detached called on incompatible receiver " + thisObj);
@@ -63,7 +63,7 @@ namespace Jint.Native.ArrayBuffer
         /// </summary>
         private JsValue ByteLength(JsValue thisObj, JsValue[] arguments)
         {
-            var o = thisObj as ArrayBufferInstance;
+            var o = thisObj as JsArrayBuffer;
             if (o is null)
             {
                 ExceptionHelper.ThrowTypeError(_realm, "Method ArrayBuffer.prototype.byteLength called on incompatible receiver " + thisObj);
@@ -87,7 +87,7 @@ namespace Jint.Native.ArrayBuffer
         /// </summary>
         private JsValue Slice(JsValue thisObj, JsValue[] arguments)
         {
-            var o = thisObj as ArrayBufferInstance;
+            var o = thisObj as JsArrayBuffer;
             if (o is null)
             {
                 ExceptionHelper.ThrowTypeError(_realm, "Method ArrayBuffer.prototype.slice called on incompatible receiver " + thisObj);
@@ -131,7 +131,7 @@ namespace Jint.Native.ArrayBuffer
 
             var newLen = System.Math.Max(final - first, 0);
             var ctor = SpeciesConstructor(o, _realm.Intrinsics.ArrayBuffer);
-            var bufferInstance = Construct(ctor, new JsValue[] { JsNumber.Create(newLen) }) as ArrayBufferInstance;
+            var bufferInstance = Construct(ctor, new JsValue[] { JsNumber.Create(newLen) }) as JsArrayBuffer;
 
             if (bufferInstance is null)
             {

+ 3 - 3
Jint/Native/ArrayBuffer/ArrayBufferInstance.cs → Jint/Native/ArrayBuffer/JsArrayBuffer.cs

@@ -7,7 +7,7 @@ namespace Jint.Native.ArrayBuffer
     /// <summary>
     /// https://tc39.es/ecma262/#sec-arraybuffer-objects
     /// </summary>
-    internal sealed class ArrayBufferInstance : ObjectInstance
+    public sealed class JsArrayBuffer : ObjectInstance
     {
         // so that we don't need to allocate while or reading setting values
         private readonly byte[] _workBuffer = new byte[8];
@@ -15,7 +15,7 @@ namespace Jint.Native.ArrayBuffer
         private byte[]? _arrayBufferData;
         private readonly JsValue _arrayBufferDetachKey = Undefined;
 
-        internal ArrayBufferInstance(
+        internal JsArrayBuffer(
             Engine engine,
             ulong byteLength) : base(engine)
         {
@@ -57,7 +57,7 @@ namespace Jint.Native.ArrayBuffer
         /// <summary>
         /// https://tc39.es/ecma262/#sec-clonearraybuffer
         /// </summary>
-        internal ArrayBufferInstance CloneArrayBuffer(
+        internal JsArrayBuffer CloneArrayBuffer(
             ArrayBufferConstructor constructor,
             int srcByteOffset,
             uint srcLength)

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

@@ -35,7 +35,7 @@ namespace Jint.Native.DataView
                 ExceptionHelper.ThrowTypeError(_realm);
             }
 
-            var buffer = arguments.At(0) as ArrayBufferInstance;
+            var buffer = arguments.At(0) as JsArrayBuffer;
             var byteOffset = arguments.At(1);
             var byteLength = arguments.At(2);
 

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

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

+ 4 - 4
Jint/Native/TypedArray/IntrinsicTypedArrayPrototype.cs

@@ -1404,7 +1404,7 @@ namespace Jint.Native.TypedArray
             return compareFn;
         }
 
-        private static JsValue[] SortArray(ArrayBufferInstance buffer, ICallable? compareFn, TypedArrayInstance obj)
+        private static JsValue[] SortArray(JsArrayBuffer buffer, ICallable? compareFn, TypedArrayInstance obj)
         {
             var comparer = TypedArrayComparer.WithFunction(buffer, compareFn);
             var operations = ArrayOperations.For(obj);
@@ -1420,16 +1420,16 @@ namespace Jint.Native.TypedArray
 
         private sealed class TypedArrayComparer : IComparer<JsValue>
         {
-            public static TypedArrayComparer WithFunction(ArrayBufferInstance buffer, ICallable? compare)
+            public static TypedArrayComparer WithFunction(JsArrayBuffer buffer, ICallable? compare)
             {
                 return new TypedArrayComparer(buffer, compare);
             }
 
-            private readonly ArrayBufferInstance _buffer;
+            private readonly JsArrayBuffer _buffer;
             private readonly ICallable? _compare;
             private readonly JsValue[] _comparableArray = new JsValue[2];
 
-            private TypedArrayComparer(ArrayBufferInstance buffer, ICallable? compare)
+            private TypedArrayComparer(JsArrayBuffer buffer, ICallable? compare)
             {
                 _buffer = buffer;
                 _compare = compare;

+ 3 - 3
Jint/Native/TypedArray/TypedArrayConstructor.cs

@@ -78,7 +78,7 @@ namespace Jint.Native.TypedArray
                 {
                     InitializeTypedArrayFromTypedArray(o, typedArrayInstance);
                 }
-                else if (firstArgument is ArrayBufferInstance arrayBuffer)
+                else if (firstArgument is JsArrayBuffer arrayBuffer)
                 {
                     var byteOffset = numberOfArgs > 1 ? args[1] : Undefined;
                     var length = numberOfArgs > 2 ? args[2] : Undefined;
@@ -137,7 +137,7 @@ namespace Jint.Native.TypedArray
             var byteLength = elementSize * elementLength;
 
             var arrayBuffer = _realm.Intrinsics.ArrayBuffer;
-            ArrayBufferInstance data;
+            JsArrayBuffer data;
             if (elementType == srcType)
             {
                 data = srcData.CloneArrayBuffer(arrayBuffer, srcByteOffset, byteLength);
@@ -175,7 +175,7 @@ namespace Jint.Native.TypedArray
         /// </summary>
         private void InitializeTypedArrayFromArrayBuffer(
             TypedArrayInstance o,
-            ArrayBufferInstance buffer,
+            JsArrayBuffer buffer,
             JsValue byteOffset,
             JsValue length)
         {

+ 2 - 2
Jint/Native/TypedArray/TypedArrayInstance.cs

@@ -12,7 +12,7 @@ namespace Jint.Native.TypedArray
     {
         internal readonly TypedArrayContentType _contentType;
         internal readonly TypedArrayElementType _arrayElementType;
-        internal ArrayBufferInstance _viewedArrayBuffer;
+        internal JsArrayBuffer _viewedArrayBuffer;
         internal uint _byteLength;
         internal int _byteOffset;
         private readonly Intrinsics _intrinsics;
@@ -25,7 +25,7 @@ namespace Jint.Native.TypedArray
             uint length) : base(engine)
         {
             _intrinsics = intrinsics;
-            _viewedArrayBuffer = new ArrayBufferInstance(engine, 0);
+            _viewedArrayBuffer = new JsArrayBuffer(engine, 0);
 
             _arrayElementType = type;
             _contentType = type != TypedArrayElementType.BigInt64 && type != TypedArrayElementType.BigUint64