Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check if length has been initialized in ArrayInstance.GetLength #761

Merged
merged 1 commit into from
Jul 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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