From fb2ac35b354b42c16b1aa760104aa26091dcb371 Mon Sep 17 00:00:00 2001
From: Tianyan Liu <tianyan.liu@movial.com>
Date: Fri, 28 Aug 2009 17:16:03 +0300
Subject: [PATCH 2/2] Added support for conversion between JSObjectRef and QVariant.

With this patch, QObject that is intended to be exported to JavaScript
can return and receive DOM objects.
---
 WebCore/bridge/qt/qt_runtime.cpp |   13 ++++++++++---
 1 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/WebCore/bridge/qt/qt_runtime.cpp b/WebCore/bridge/qt/qt_runtime.cpp
index 2212f58..a95b3eb 100644
--- a/WebCore/bridge/qt/qt_runtime.cpp
+++ b/WebCore/bridge/qt/qt_runtime.cpp
@@ -54,6 +54,10 @@
 #include <runtime_array.h>
 #include <runtime_object.h>
 
+#include <JavaScriptCore/APICast.h>
+// Register JSObjectRef as a QMetaType for using with QVariant*/
+Q_DECLARE_METATYPE(JSObjectRef);
+
 // QtScript has these
 Q_DECLARE_METATYPE(QObjectList);
 Q_DECLARE_METATYPE(QList<int>);
@@ -637,8 +641,9 @@ QVariant convertValueToQVariant(ExecState* exec, JSValue value, QMetaType::Type
 
         default:
             // Non const type ids
-            if (hint == (QMetaType::Type) qMetaTypeId<QObjectList>())
-            {
+            if (hint == (QMetaType::Type) qMetaTypeId<JSObjectRef>()) {
+                ret = QVariant::fromValue(toRef(object));
+            } else if (hint == (QMetaType::Type) qMetaTypeId<QObjectList>()) {
                 if (type == RTArray) {
                     RuntimeArray* rtarray = static_cast<RuntimeArray*>(object);
 
@@ -913,7 +918,9 @@ JSValue convertQVariantToValue(ExecState* exec, PassRefPtr<RootObject> root, con
     }
 
     // List types
-    if (type == QMetaType::QVariantList) {
+    if (type == (QMetaType::Type) qMetaTypeId<JSObjectRef>()) {
+        return toJS(variant.value<JSObjectRef>());
+    } else if (type == QMetaType::QVariantList) {
         QVariantList vl = variant.toList();
         qConvDebug() << "got a " << vl.count() << " length list:" << vl;
         return new (exec) RuntimeArray(exec, new QtArray<QVariant>(vl, QMetaType::Void, root));
-- 
1.6.3.3


