using System.Diagnostics;
using Jint.Native.Array;
namespace Jint.Native;
[DebuggerTypeProxy(typeof(JsArrayDebugView))]
[DebuggerDisplay("Count = {Length}")]
public sealed class JsArray : ArrayInstance
{
///
/// Creates a new array instance with defaults.
///
/// The engine that this array is bound to.
/// The initial size of underlying data structure, if you know you're going to add N items, provide N.
/// Sets the length of the array.
public JsArray(Engine engine, uint capacity = 0, uint length = 0) : base(engine, capacity, length)
{
}
///
/// Possibility to construct valid array fast.
/// The array will be owned and modified by Jint afterwards.
///
public JsArray(Engine engine, JsValue[] items) : base(engine, items)
{
}
public uint Length => GetLength();
private sealed class JsArrayDebugView
{
private readonly JsArray _array;
public JsArrayDebugView(JsArray array)
{
_array = array;
}
[DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
public JsValue[] Values
{
get
{
var values = new JsValue[_array.GetLength()];
var i = 0;
foreach (var value in _array)
{
values[i++] = value;
}
return values;
}
}
}
}