Skip to content

Commit

Permalink
Check if length has been initialized in ArrayInstance.GetLength (#761)
Browse files Browse the repository at this point in the history
  • Loading branch information
lahma authored Jul 19, 2020
1 parent 5d1114d commit 11b0173
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Jint.Tests/Runtime/ArrayTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Jint.Native.Array;
using Xunit;

namespace Jint.Tests.Runtime
Expand Down Expand Up @@ -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);
}
}
}
5 changes: 5 additions & 0 deletions Jint/Native/Array/ArrayInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 11b0173

Please sign in to comment.