diff --git a/src/native/QmlNet/QmlNet/qml/JsNetArray.cpp b/src/native/QmlNet/QmlNet/qml/JsNetArray.cpp index 0eaf9782..7ce1b127 100644 --- a/src/native/QmlNet/QmlNet/qml/JsNetArray.cpp +++ b/src/native/QmlNet/QmlNet/qml/JsNetArray.cpp @@ -52,7 +52,7 @@ ReturnedValue NetArray::method_length(const FunctionObject *b, const Value *this THROW_GENERIC_ERROR("The wrapped object can't be treated as an array."); } - return Encode(scope.engine->newNumberObject(arrayFacade->getLength(netValue->getNetReference()))); + return Encode(arrayFacade->getLength(netValue->getNetReference())); } ReturnedValue NetArray::getIndexed(const Managed *m, uint index, bool *hasProperty) diff --git a/src/net/Qml.Net.Tests/Qml/ArrayTests.cs b/src/net/Qml.Net.Tests/Qml/ArrayTests.cs new file mode 100644 index 00000000..0582e04a --- /dev/null +++ b/src/net/Qml.Net.Tests/Qml/ArrayTests.cs @@ -0,0 +1,39 @@ +using Moq; +using Xunit; + +namespace Qml.Net.Tests.Qml +{ + public class ArrayTests : BaseQmlTests + { + public class ArrayTestsQml + { + public virtual int[] GetArray() + { + return null; + } + + public virtual void Test(object value) + { + + } + } + + [Fact] + public void Can_get_length() + { + var array = new[] {3, 4, 6}; + Mock.Setup(x => x.GetArray()).Returns(array); + Mock.Setup(x => x.Test(3)); + + RunQmlTest( + "test", + @" + var array = Net.toJsArray(test.getArray()) + test.test(array.length) + "); + + Mock.Verify(x => x.GetArray(), Times.Once); + Mock.Verify(x => x.Test(3), Times.Once); + } + } +} \ No newline at end of file