Skip to content

Commit

Permalink
Rename ArrayBufferInstance to JsArrayBuffer and make it public (#1591)
Browse files Browse the repository at this point in the history
  • Loading branch information
lahma authored Jul 28, 2023
1 parent 4057029 commit 2ce1349
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Jint.Tests.Test262/Test262Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
4 changes: 2 additions & 2 deletions Jint/Native/ArrayBuffer/ArrayBufferConstructor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions Jint/Native/ArrayBuffer/ArrayBufferPrototype.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -63,7 +63,7 @@ private JsValue Detached(JsValue thisObj, JsValue[] arguments)
/// </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);
Expand All @@ -87,7 +87,7 @@ private JsValue ByteLength(JsValue thisObj, JsValue[] arguments)
/// </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);
Expand Down Expand Up @@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ 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];

private byte[]? _arrayBufferData;
private readonly JsValue _arrayBufferDetachKey = Undefined;

internal ArrayBufferInstance(
internal JsArrayBuffer(
Engine engine,
ulong byteLength) : base(engine)
{
Expand Down Expand Up @@ -57,7 +57,7 @@ internal void DetachArrayBuffer(JsValue? key = null)
/// <summary>
/// https://tc39.es/ecma262/#sec-clonearraybuffer
/// </summary>
internal ArrayBufferInstance CloneArrayBuffer(
internal JsArrayBuffer CloneArrayBuffer(
ArrayBufferConstructor constructor,
int srcByteOffset,
uint srcLength)
Expand Down
2 changes: 1 addition & 1 deletion Jint/Native/DataView/DataViewConstructor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion Jint/Native/DataView/DataViewInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
8 changes: 4 additions & 4 deletions Jint/Native/TypedArray/IntrinsicTypedArrayPrototype.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -1420,16 +1420,16 @@ private static JsValue[] SortArray(ArrayBufferInstance buffer, ICallable? compar

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;
Expand Down
6 changes: 3 additions & 3 deletions Jint/Native/TypedArray/TypedArrayConstructor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -175,7 +175,7 @@ private void InitializeTypedArrayFromTypedArray(TypedArrayInstance o, TypedArray
/// </summary>
private void InitializeTypedArrayFromArrayBuffer(
TypedArrayInstance o,
ArrayBufferInstance buffer,
JsArrayBuffer buffer,
JsValue byteOffset,
JsValue length)
{
Expand Down
4 changes: 2 additions & 2 deletions Jint/Native/TypedArray/TypedArrayInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down

0 comments on commit 2ce1349

Please sign in to comment.