From 2ce134903933977e4810ea43932240530aa8b47c Mon Sep 17 00:00:00 2001 From: Marko Lahma Date: Fri, 28 Jul 2023 21:13:22 +0300 Subject: [PATCH] Rename ArrayBufferInstance to JsArrayBuffer and make it public (#1591) --- Jint.Tests.Test262/Test262Test.cs | 2 +- Jint/Native/ArrayBuffer/ArrayBufferConstructor.cs | 4 ++-- Jint/Native/ArrayBuffer/ArrayBufferPrototype.cs | 8 ++++---- .../{ArrayBufferInstance.cs => JsArrayBuffer.cs} | 6 +++--- Jint/Native/DataView/DataViewConstructor.cs | 2 +- Jint/Native/DataView/DataViewInstance.cs | 2 +- Jint/Native/TypedArray/IntrinsicTypedArrayPrototype.cs | 8 ++++---- Jint/Native/TypedArray/TypedArrayConstructor.cs | 6 +++--- Jint/Native/TypedArray/TypedArrayInstance.cs | 4 ++-- 9 files changed, 21 insertions(+), 21 deletions(-) rename Jint/Native/ArrayBuffer/{ArrayBufferInstance.cs => JsArrayBuffer.cs} (98%) diff --git a/Jint.Tests.Test262/Test262Test.cs b/Jint.Tests.Test262/Test262Test.cs index 2d5f8f0dac..6bbac100e4 100644 --- a/Jint.Tests.Test262/Test262Test.cs +++ b/Jint.Tests.Test262/Test262Test.cs @@ -56,7 +56,7 @@ private Engine BuildTestExecutor(Test262File file) 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)); diff --git a/Jint/Native/ArrayBuffer/ArrayBufferConstructor.cs b/Jint/Native/ArrayBuffer/ArrayBufferConstructor.cs index abd4f9c2ef..03a549d1a4 100644 --- a/Jint/Native/ArrayBuffer/ArrayBufferConstructor.cs +++ b/Jint/Native/ArrayBuffer/ArrayBufferConstructor.cs @@ -76,12 +76,12 @@ public override ObjectInstance Construct(JsValue[] arguments, JsValue newTarget) 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; diff --git a/Jint/Native/ArrayBuffer/ArrayBufferPrototype.cs b/Jint/Native/ArrayBuffer/ArrayBufferPrototype.cs index 0f118a0857..dcf9d8414c 100644 --- a/Jint/Native/ArrayBuffer/ArrayBufferPrototype.cs +++ b/Jint/Native/ArrayBuffer/ArrayBufferPrototype.cs @@ -44,7 +44,7 @@ protected override void Initialize() 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 @@ private JsValue Detached(JsValue thisObj, JsValue[] arguments) /// 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 @@ private JsValue ByteLength(JsValue thisObj, JsValue[] arguments) /// 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 @@ private JsValue Slice(JsValue thisObj, JsValue[] arguments) 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) { diff --git a/Jint/Native/ArrayBuffer/ArrayBufferInstance.cs b/Jint/Native/ArrayBuffer/JsArrayBuffer.cs similarity index 98% rename from Jint/Native/ArrayBuffer/ArrayBufferInstance.cs rename to Jint/Native/ArrayBuffer/JsArrayBuffer.cs index 2c17538fea..c745a66ce6 100644 --- a/Jint/Native/ArrayBuffer/ArrayBufferInstance.cs +++ b/Jint/Native/ArrayBuffer/JsArrayBuffer.cs @@ -7,7 +7,7 @@ namespace Jint.Native.ArrayBuffer /// /// https://tc39.es/ecma262/#sec-arraybuffer-objects /// - 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 @@ internal sealed class ArrayBufferInstance : ObjectInstance private byte[]? _arrayBufferData; private readonly JsValue _arrayBufferDetachKey = Undefined; - internal ArrayBufferInstance( + internal JsArrayBuffer( Engine engine, ulong byteLength) : base(engine) { @@ -57,7 +57,7 @@ internal void DetachArrayBuffer(JsValue? key = null) /// /// https://tc39.es/ecma262/#sec-clonearraybuffer /// - internal ArrayBufferInstance CloneArrayBuffer( + internal JsArrayBuffer CloneArrayBuffer( ArrayBufferConstructor constructor, int srcByteOffset, uint srcLength) diff --git a/Jint/Native/DataView/DataViewConstructor.cs b/Jint/Native/DataView/DataViewConstructor.cs index 4f940a7159..2d14e17e10 100644 --- a/Jint/Native/DataView/DataViewConstructor.cs +++ b/Jint/Native/DataView/DataViewConstructor.cs @@ -35,7 +35,7 @@ public override ObjectInstance Construct(JsValue[] arguments, JsValue newTarget) 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); diff --git a/Jint/Native/DataView/DataViewInstance.cs b/Jint/Native/DataView/DataViewInstance.cs index 17f06d34f2..eff16b1ff4 100644 --- a/Jint/Native/DataView/DataViewInstance.cs +++ b/Jint/Native/DataView/DataViewInstance.cs @@ -8,7 +8,7 @@ namespace Jint.Native.DataView; /// internal sealed class DataViewInstance : ObjectInstance { - internal ArrayBufferInstance? _viewedArrayBuffer; + internal JsArrayBuffer? _viewedArrayBuffer; internal uint _byteLength; internal uint _byteOffset; diff --git a/Jint/Native/TypedArray/IntrinsicTypedArrayPrototype.cs b/Jint/Native/TypedArray/IntrinsicTypedArrayPrototype.cs index 54c361eaac..89c8f5fcfc 100644 --- a/Jint/Native/TypedArray/IntrinsicTypedArrayPrototype.cs +++ b/Jint/Native/TypedArray/IntrinsicTypedArrayPrototype.cs @@ -1404,7 +1404,7 @@ private TypedArrayInstance TypedArrayCreateSameType(TypedArrayInstance exemplar, 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 @@ private static JsValue[] SortArray(ArrayBufferInstance buffer, ICallable? compar private sealed class TypedArrayComparer : IComparer { - 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; diff --git a/Jint/Native/TypedArray/TypedArrayConstructor.cs b/Jint/Native/TypedArray/TypedArrayConstructor.cs index d71943b0da..b25f7de3b9 100644 --- a/Jint/Native/TypedArray/TypedArrayConstructor.cs +++ b/Jint/Native/TypedArray/TypedArrayConstructor.cs @@ -78,7 +78,7 @@ public override ObjectInstance Construct(JsValue[] args, JsValue newTarget) { 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 @@ private void InitializeTypedArrayFromTypedArray(TypedArrayInstance o, 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 @@ private void InitializeTypedArrayFromTypedArray(TypedArrayInstance o, TypedArray /// private void InitializeTypedArrayFromArrayBuffer( TypedArrayInstance o, - ArrayBufferInstance buffer, + JsArrayBuffer buffer, JsValue byteOffset, JsValue length) { diff --git a/Jint/Native/TypedArray/TypedArrayInstance.cs b/Jint/Native/TypedArray/TypedArrayInstance.cs index 153e4783ca..0295a96953 100644 --- a/Jint/Native/TypedArray/TypedArrayInstance.cs +++ b/Jint/Native/TypedArray/TypedArrayInstance.cs @@ -12,7 +12,7 @@ public sealed class TypedArrayInstance : ObjectInstance { 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 @@ internal TypedArrayInstance( 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