{
m_engine = engine;
v8::Local<v8::FunctionTemplate> ft = v8::FunctionTemplate::New();
- ft->InstanceTemplate()->SetFallbackPropertyHandler(Getter, Setter);
+ ft->InstanceTemplate()->SetFallbackPropertyHandler(Getter, Setter, 0, 0, Enumerator);
ft->InstanceTemplate()->SetIndexedPropertyHandler(IndexedGetter);
ft->InstanceTemplate()->SetAccessor(v8::String::New("length"), LengthGetter, 0,
v8::Handle<v8::Value>(), v8::DEFAULT,
- v8::PropertyAttribute(v8::ReadOnly | v8::DontDelete));
+ v8::PropertyAttribute(v8::ReadOnly | v8::DontDelete | v8::DontEnum));
ft->InstanceTemplate()->SetHasExternalResource(true);
m_constructor = qPersistentNew<v8::Function>(ft->GetFunction());
}
return v8::Integer::NewFromUnsigned(count);
}
+v8::Handle<v8::Array> QV8ListWrapper::Enumerator(const v8::AccessorInfo &info)
+{
+ QV8ListResource *resource = v8_resource_cast<QV8ListResource>(info.This());
+
+ if (!resource || resource->object.isNull()) return v8::Array::New();
+
+ quint32 count = resource->property.count?resource->property.count(&resource->property):0;
+
+ v8::Local<v8::Array> rv = v8::Array::New(count);
+
+ for (int ii = 0; ii < count; ++ii)
+ rv->Set(ii, v8::Number::New(ii));
+
+ return rv;
+}
+
QT_END_NAMESPACE
const v8::AccessorInfo &info);
static v8::Handle<v8::Value> LengthGetter(v8::Local<v8::String> property,
const v8::AccessorInfo &info);
+ static v8::Handle<v8::Array> Enumerator(const v8::AccessorInfo &info);
QV8Engine *m_engine;
v8::Persistent<v8::Function> m_constructor;
--- /dev/null
+import QtQuick 2.0
+
+QtObject {
+ property list<QtObject> objects
+ objects: [QtObject { objectName: "obj1" }, QtObject { objectName: "obj2" }, QtObject { objectName: "obj3" }]
+ property string listResult
+
+ function listProperty() {
+ for (var i in objects)
+ listResult += i + "=" + objects[i].objectName + "|"
+ }
+}
+
void include();
void signalHandlers();
void doubleEvaluate();
+ void forInLoop();
void callQtInvokables();
void invokableObjectArg();
delete object;
}
+void tst_qdeclarativeecmascript::forInLoop()
+{
+ QDeclarativeComponent component(&engine, TEST_FILE("forInLoop.qml"));
+ QObject *object = component.create();
+ QVERIFY(object != 0);
+
+ QMetaObject::invokeMethod(object, "listProperty");
+
+ QStringList r = object->property("listResult").toString().split("|", QString::SkipEmptyParts);
+ QCOMPARE(r.size(), 3);
+ QCOMPARE(r[0],QLatin1String("0=obj1"));
+ QCOMPARE(r[1],QLatin1String("1=obj2"));
+ QCOMPARE(r[2],QLatin1String("2=obj3"));
+
+ //TODO: should test for in loop for other objects (such as QObjects) as well.
+
+ delete object;
+}
+
QTEST_MAIN(tst_qdeclarativeecmascript)
#include "tst_qdeclarativeecmascript.moc"