Enable support for QObject based module APIs
authorAaron Kennedy <aaron.kennedy@nokia.com>
Tue, 12 Jul 2011 06:46:09 +0000 (16:46 +1000)
committerQt by Nokia <qt-info@nokia.com>
Tue, 12 Jul 2011 06:47:14 +0000 (08:47 +0200)
Task-number: QTBUG-17318

Change-Id: Ia887f563b337b1c34ff65a0559bb7f33c18b4e28
Reviewed-on: http://codereview.qt.nokia.com/1479
Reviewed-by: Aaron Kennedy <aaron.kennedy@nokia.com>
src/declarative/qml/v8/qv8typewrapper.cpp
tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp

index 9aac7a3..39d03db 100644 (file)
@@ -172,10 +172,24 @@ v8::Handle<v8::Value> QV8TypeWrapper::Getter(v8::Local<v8::String> property,
         if (d && d->type) {
             return v8engine->typeWrapper()->newObject(object, d->type, resource->mode);
         } else if (QDeclarativeMetaType::ModuleApiInstance *moduleApi = typeNamespace->moduleApi()) {
-            // XXX TODO: Currently module APIs are implemented against QScriptValues.  Consequently we
-            // can't do anything here until the QtScript/V8 binding is complete.
-            return v8::Undefined();
 
+            // XXX TODO: Currently module APIs are implemented against QScriptValues.  Consequently we
+            // can't do anything for script module apis here until the QtScript/V8 binding is complete.
+            if (moduleApi->qobjectCallback) {
+                moduleApi->qobjectApi = moduleApi->qobjectCallback(v8engine->engine(), 0);
+                moduleApi->scriptCallback = 0;
+                moduleApi->qobjectCallback = 0;
+            }
+
+            if (moduleApi->qobjectApi) {
+                v8::Handle<v8::Value> rv = v8engine->qobjectWrapper()->getProperty(moduleApi->qobjectApi, propertystring, QV8QObjectWrapper::IgnoreRevision);
+                if (rv.IsEmpty())
+                    return v8::Undefined();
+                else 
+                    return rv;
+            } else {
+                return v8::Undefined();
+            }
         }
 
         // Fall through to undefined
@@ -209,6 +223,20 @@ v8::Handle<v8::Value> QV8TypeWrapper::Setter(v8::Local<v8::String> property,
         if (ao) 
             v8engine->qobjectWrapper()->setProperty(ao, propertystring, value, 
                                                     QV8QObjectWrapper::IgnoreRevision);
+    } else if (resource->typeNamespace) {
+        if (QDeclarativeMetaType::ModuleApiInstance *moduleApi = resource->typeNamespace->moduleApi()) {
+            // XXX TODO: Currently module APIs are implemented against QScriptValues.  Consequently we
+            // can't do anything for script module apis here until the QtScript/V8 binding is complete.
+            if (moduleApi->qobjectCallback) {
+                moduleApi->qobjectApi = moduleApi->qobjectCallback(v8engine->engine(), 0);
+                moduleApi->scriptCallback = 0;
+                moduleApi->qobjectCallback = 0;
+            }
+
+            if (moduleApi->qobjectApi) 
+                v8engine->qobjectWrapper()->setProperty(moduleApi->qobjectApi, propertystring, value, 
+                                                        QV8QObjectWrapper::IgnoreRevision);
+        }
     }
 
     return value;
index 6f87640..22c2096 100644 (file)
@@ -2585,12 +2585,12 @@ void tst_qdeclarativeecmascript::signalWithUnknownTypes()
 
 void tst_qdeclarativeecmascript::moduleApi()
 {
-    QSKIP("Module API not supported with V8", SkipAll);
-
     QDeclarativeComponent component(&engine, TEST_FILE("moduleApi.qml"));
     QObject *object = component.create();
     QVERIFY(object != 0);
     QCOMPARE(object->property("existingUriTest").toInt(), 20);
+
+    QEXPECT_FAIL("", "QTBUG-17318", Continue);
     QCOMPARE(object->property("scriptTest").toInt(), 13);
     QCOMPARE(object->property("qobjectTest").toInt(), 20);
     QCOMPARE(object->property("qobjectMethodTest").toInt(), 1); // first call of method, so count = 1.
@@ -2604,6 +2604,7 @@ void tst_qdeclarativeecmascript::moduleApi()
     object = componentTwo.create();
     QVERIFY(object != 0);
     QCOMPARE(object->property("existingUriTest").toInt(), 20);
+    QEXPECT_FAIL("", "QTBUG-17318", Continue);
     QCOMPARE(object->property("scriptTest").toInt(), 13);            // shouldn't have incremented.
     QCOMPARE(object->property("qobjectParentedTest").toInt(), 26);   // shouldn't have incremented.
     delete object;