diff --git a/Jint.Tests/Runtime/ArrayTests.cs b/Jint.Tests/Runtime/ArrayTests.cs index 5df1582f0c..95feaa8a66 100644 --- a/Jint.Tests/Runtime/ArrayTests.cs +++ b/Jint.Tests/Runtime/ArrayTests.cs @@ -1,4 +1,5 @@ using System; +using Jint.Native.Array; using Xunit; namespace Jint.Tests.Runtime @@ -64,5 +65,14 @@ public void LargeArraySize() var engine = new Engine(); engine.Execute(code); } + + [Fact] + public void ArrayLengthFromInitialState() + { + var engine = new Engine(); + var array = new ArrayInstance(engine, 0); + var length = (int) array.Length; + Assert.Equal(0, length); + } } } \ No newline at end of file diff --git a/Jint/Native/Array/ArrayInstance.cs b/Jint/Native/Array/ArrayInstance.cs index a33c76234a..dbe651d36f 100644 --- a/Jint/Native/Array/ArrayInstance.cs +++ b/Jint/Native/Array/ArrayInstance.cs @@ -222,6 +222,11 @@ public override bool DefineOwnProperty(JsValue property, PropertyDescriptor desc [MethodImpl(MethodImplOptions.AggressiveInlining)] internal uint GetLength() { + if (_length is null) + { + return 0; + } + return (uint) ((JsNumber) _length._value)._value; }