diff --git a/src/native/QmlNet/QmlNet/qml/JsNetArray.h b/src/native/QmlNet/QmlNet/qml/JsNetArray.h index 6539e0f1..687f4f5e 100644 --- a/src/native/QmlNet/QmlNet/qml/JsNetArray.h +++ b/src/native/QmlNet/QmlNet/qml/JsNetArray.h @@ -21,6 +21,8 @@ struct NetArray : Object V4_OBJECT2(NetArray, Object) V4_NEEDS_DESTROY Q_MANAGED_TYPE(ArrayObject) + V4_PROTOTYPE(arrayPrototype) + static ReturnedValue create(ExecutionEngine *engine, NetValue* netValue); static ReturnedValue method_length(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); diff --git a/src/native/QmlNet/QmlNet/types/NetTypeArrayFacade.cpp b/src/native/QmlNet/QmlNet/types/NetTypeArrayFacade.cpp index 6d9f2720..f66e007a 100644 --- a/src/native/QmlNet/QmlNet/types/NetTypeArrayFacade.cpp +++ b/src/native/QmlNet/QmlNet/types/NetTypeArrayFacade.cpp @@ -21,7 +21,7 @@ QSharedPointer NetTypeArrayFacade::fromType(QSharedPointer) +uint NetTypeArrayFacade::getLength(QSharedPointer) { return 0; } diff --git a/src/native/QmlNet/QmlNet/types/NetTypeArrayFacade.h b/src/native/QmlNet/QmlNet/types/NetTypeArrayFacade.h index 4447b7ae..8671f297 100644 --- a/src/native/QmlNet/QmlNet/types/NetTypeArrayFacade.h +++ b/src/native/QmlNet/QmlNet/types/NetTypeArrayFacade.h @@ -14,7 +14,7 @@ public: NetTypeArrayFacade(); virtual ~NetTypeArrayFacade() {} static QSharedPointer fromType(QSharedPointer type); - virtual int getLength(QSharedPointer reference); + virtual uint getLength(QSharedPointer reference); virtual QSharedPointer getIndexed(QSharedPointer reference, int index); virtual void setIndexed(QSharedPointer reference, int index, QSharedPointer value); }; diff --git a/src/native/QmlNet/QmlNet/types/NetTypeArrayFacadeArray.cpp b/src/native/QmlNet/QmlNet/types/NetTypeArrayFacadeArray.cpp index 3400aa9d..e85aada3 100644 --- a/src/native/QmlNet/QmlNet/types/NetTypeArrayFacadeArray.cpp +++ b/src/native/QmlNet/QmlNet/types/NetTypeArrayFacadeArray.cpp @@ -38,11 +38,11 @@ bool NetTypeArrayFacade_Array::isIncomplete() return _isIncomplete; } -int NetTypeArrayFacade_Array::getLength(QSharedPointer reference) +uint NetTypeArrayFacade_Array::getLength(QSharedPointer reference) { QSharedPointer result = QSharedPointer(new NetVariant()); readProperty(_lengthProperty, reference, result); - return result->getInt(); + return static_cast(result->getInt()); } QSharedPointer NetTypeArrayFacade_Array::getIndexed(QSharedPointer reference, int index) diff --git a/src/native/QmlNet/QmlNet/types/NetTypeArrayFacadeArray.h b/src/native/QmlNet/QmlNet/types/NetTypeArrayFacadeArray.h index 66275078..2bca4bcc 100644 --- a/src/native/QmlNet/QmlNet/types/NetTypeArrayFacadeArray.h +++ b/src/native/QmlNet/QmlNet/types/NetTypeArrayFacadeArray.h @@ -11,7 +11,7 @@ class NetTypeArrayFacade_Array : public NetTypeArrayFacade public: NetTypeArrayFacade_Array(QSharedPointer type); bool isIncomplete(); - int getLength(QSharedPointer reference); + uint getLength(QSharedPointer reference); QSharedPointer getIndexed(QSharedPointer reference, int index); void setIndexed(QSharedPointer reference, int index, QSharedPointer value); private: diff --git a/src/net/Qml.Net.Tests/Qml/ArrayTests.cs b/src/net/Qml.Net.Tests/Qml/ArrayTests.cs index b819ddb4..0bb440bb 100644 --- a/src/net/Qml.Net.Tests/Qml/ArrayTests.cs +++ b/src/net/Qml.Net.Tests/Qml/ArrayTests.cs @@ -71,5 +71,26 @@ namespace Qml.Net.Tests.Qml Mock.Verify(x => x.GetArray(), Times.Once); array[2].Should().Be(234); } + + [Fact] + public void Can_forEach() + { + var array = new[] {3, 4, 7}; + Mock.Setup(x => x.GetArray()).Returns(array); + + RunQmlTest( + "test", + @" + var array = Net.toJsArray(test.getArray()) + array.forEach(function(value) { + test.test(value) + }) + "); + + Mock.Verify(x => x.GetArray(), Times.Once); + Mock.Verify(x => x.Test(3), Times.Once); + Mock.Verify(x => x.Test(4), Times.Once); + Mock.Verify(x => x.Test(7), Times.Once); + } } } \ No newline at end of file diff --git a/src/net/Qml.Net.Tests/Types/NetTypeManagerTests.cs b/src/net/Qml.Net.Tests/Types/NetTypeManagerTests.cs index d74bf580..fda6bb53 100644 --- a/src/net/Qml.Net.Tests/Types/NetTypeManagerTests.cs +++ b/src/net/Qml.Net.Tests/Types/NetTypeManagerTests.cs @@ -265,7 +265,7 @@ namespace Qml.Net.Tests.Types type.GetStaticMethod(0).MethodName.Should().Be("StaticMethod"); } - public class TestType12 + public class TestType13 { public string[] Property { get; set; } } @@ -273,7 +273,7 @@ namespace Qml.Net.Tests.Types [Fact] public void Can_detect_array_type() { - var type = NetTypeManager.GetTypeInfo(); + var type = NetTypeManager.GetTypeInfo(); type.EnsureLoaded(); var property = type.GetProperty(0); var returnType = property.ReturnType; diff --git a/src/net/Qml.Net/Internal/DefaultCallbacks.cs b/src/net/Qml.Net/Internal/DefaultCallbacks.cs index fddf05c5..18632466 100644 --- a/src/net/Qml.Net/Internal/DefaultCallbacks.cs +++ b/src/net/Qml.Net/Internal/DefaultCallbacks.cs @@ -49,7 +49,6 @@ namespace Qml.Net.Internal type.IsArray = typeInfo.IsArray; - foreach (var methodInfo in typeInfo.GetMethods(BindingFlags.Public | BindingFlags.Instance)) foreach (var methodInfo in typeInfo.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static)) { if (methodInfo.IsGenericMethod) continue; // No generics supported.