Title: [120196] trunk/Source
Revision
120196
Author
[email protected]
Date
2012-06-13 06:37:54 -0700 (Wed, 13 Jun 2012)

Log Message

[Qt] Remove dependency to QtScript for the Qt 5 build
https://bugs.webkit.org/show_bug.cgi?id=88993

Reviewed by Kenneth Rohde Christiansen.

Source/WebCore:

Replace the use of QScriptEngine::ValueOwnership with an enum local
to the class where it is used (QtInstance).

* Target.pri:
* bindings/js/ScriptControllerQt.cpp:
(WebCore::ScriptController::createScriptInstanceForWidget):
* bridge/qt/qt_instance.cpp:
(JSC::Bindings::QtInstance::QtInstance):
(JSC::Bindings::QtInstance::~QtInstance):
(JSC::Bindings::QtInstance::getQtInstance):
* bridge/qt/qt_instance.h:
(QtInstance):
(JSC::Bindings::QtInstance::create):
* bridge/qt/qt_runtime.cpp:
(JSC::Bindings::convertQVariantToValue):
* bridge/qt/qt_runtime_qt4.cpp:
(JSC::Bindings::convertQVariantToValue):

Source/WebKit/qt:

When building against Qt 5, replace the use of QScriptEngine::ValueOwnership with
a (compatible) QWebFrame::ValueOwnership enum.

* Api/qwebframe.cpp:
(qtSenderCallback):
(QWebFrame::addToJavaScriptWindowObject):
* Api/qwebframe.h:
* tests/qobjectbridge/tst_qobjectbridge.cpp:
(tst_QObjectBridge::arrayObjectEnumerable):
(tst_QObjectBridge::ownership):
(tst_QObjectBridge::qObjectWrapperWithSameIdentity):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (120195 => 120196)


--- trunk/Source/WebCore/ChangeLog	2012-06-13 13:11:24 UTC (rev 120195)
+++ trunk/Source/WebCore/ChangeLog	2012-06-13 13:37:54 UTC (rev 120196)
@@ -1,3 +1,28 @@
+2012-06-13  Simon Hausmann  <[email protected]>
+
+        [Qt] Remove dependency to QtScript for the Qt 5 build
+        https://bugs.webkit.org/show_bug.cgi?id=88993
+
+        Reviewed by Kenneth Rohde Christiansen.
+
+        Replace the use of QScriptEngine::ValueOwnership with an enum local
+        to the class where it is used (QtInstance).
+
+        * Target.pri:
+        * bindings/js/ScriptControllerQt.cpp:
+        (WebCore::ScriptController::createScriptInstanceForWidget):
+        * bridge/qt/qt_instance.cpp:
+        (JSC::Bindings::QtInstance::QtInstance):
+        (JSC::Bindings::QtInstance::~QtInstance):
+        (JSC::Bindings::QtInstance::getQtInstance):
+        * bridge/qt/qt_instance.h:
+        (QtInstance):
+        (JSC::Bindings::QtInstance::create):
+        * bridge/qt/qt_runtime.cpp:
+        (JSC::Bindings::convertQVariantToValue):
+        * bridge/qt/qt_runtime_qt4.cpp:
+        (JSC::Bindings::convertQVariantToValue):
+
 2012-06-13  Caio Marcelo de Oliveira Filho  <[email protected]>
 
         [Qt] Save a JSGlobalContextRef instead of a JSContextRef in QtConnectionObject

Modified: trunk/Source/WebCore/Target.pri (120195 => 120196)


--- trunk/Source/WebCore/Target.pri	2012-06-13 13:11:24 UTC (rev 120195)
+++ trunk/Source/WebCore/Target.pri	2012-06-13 13:37:54 UTC (rev 120196)
@@ -16,11 +16,7 @@
 
 DEFINES += QT_MAKEDLL
 
-haveQt(5) {
-    # Add a QtScript dependency for the time being, in order to pull in the include
-    # path for QtScript when it's built as a standalone module
-    QT += script
-} else {
+!haveQt(5) {
     INCLUDEPATH += $$PWD/../WTF/wtf/qt/compat
 }
 

Modified: trunk/Source/WebCore/bindings/js/ScriptControllerQt.cpp (120195 => 120196)


--- trunk/Source/WebCore/bindings/js/ScriptControllerQt.cpp	2012-06-13 13:11:24 UTC (rev 120195)
+++ trunk/Source/WebCore/bindings/js/ScriptControllerQt.cpp	2012-06-13 13:37:54 UTC (rev 120196)
@@ -59,7 +59,7 @@
     if (!object)
         return 0;
 
-    return JSC::Bindings::QtInstance::getQtInstance(object, bindingRootObject(), QScriptEngine::QtOwnership);
+    return JSC::Bindings::QtInstance::getQtInstance(object, bindingRootObject(), JSC::Bindings::QtInstance::QtOwnership);
 }
 
 }

Modified: trunk/Source/WebCore/bridge/qt/qt_instance.cpp (120195 => 120196)


--- trunk/Source/WebCore/bridge/qt/qt_instance.cpp	2012-06-13 13:11:24 UTC (rev 120195)
+++ trunk/Source/WebCore/bridge/qt/qt_instance.cpp	2012-06-13 13:37:54 UTC (rev 120196)
@@ -81,7 +81,7 @@
 }
 
 // QtInstance
-QtInstance::QtInstance(QObject* o, PassRefPtr<RootObject> rootObject, QScriptEngine::ValueOwnership ownership)
+QtInstance::QtInstance(QObject* o, PassRefPtr<RootObject> rootObject, ValueOwnership ownership)
     : Instance(rootObject)
     , m_class(0)
     , m_object(o)
@@ -104,20 +104,20 @@
 
     if (m_object) {
         switch (m_ownership) {
-        case QScriptEngine::QtOwnership:
+        case QtOwnership:
             break;
-        case QScriptEngine::AutoOwnership:
+        case AutoOwnership:
             if (m_object.data()->parent())
                 break;
             // fall through!
-        case QScriptEngine::ScriptOwnership:
+        case ScriptOwnership:
             delete m_object.data();
             break;
         }
     }
 }
 
-PassRefPtr<QtInstance> QtInstance::getQtInstance(QObject* o, PassRefPtr<RootObject> rootObject, QScriptEngine::ValueOwnership ownership)
+PassRefPtr<QtInstance> QtInstance::getQtInstance(QObject* o, PassRefPtr<RootObject> rootObject, ValueOwnership ownership)
 {
     JSLock lock(SilenceAssertionsOnly);
 

Modified: trunk/Source/WebCore/bridge/qt/qt_instance.h (120195 => 120196)


--- trunk/Source/WebCore/bridge/qt/qt_instance.h	2012-06-13 13:11:24 UTC (rev 120195)
+++ trunk/Source/WebCore/bridge/qt/qt_instance.h	2012-06-13 13:37:54 UTC (rev 120196)
@@ -23,7 +23,6 @@
 #include "BridgeJSC.h"
 #include <QStack>
 #include <QWeakPointer>
-#include <QtScript/qscriptengine.h>
 #include "Weak.h"
 #include "runtime_root.h"
 #include <qhash.h>
@@ -39,6 +38,12 @@
 
 class QtInstance : public Instance {
 public:
+    enum ValueOwnership {
+        QtOwnership,
+        ScriptOwnership,
+        AutoOwnership
+    };
+
     ~QtInstance();
 
     virtual Class* getClass() const;
@@ -62,7 +67,7 @@
     QObject* getObject() const { return m_object.data(); }
     QObject* hashKey() const { return m_hashkey; }
 
-    static PassRefPtr<QtInstance> getQtInstance(QObject*, PassRefPtr<RootObject>, QScriptEngine::ValueOwnership ownership);
+    static PassRefPtr<QtInstance> getQtInstance(QObject*, PassRefPtr<RootObject>, ValueOwnership);
 
     virtual bool getOwnPropertySlot(JSObject*, ExecState*, PropertyName, PropertySlot&);
     virtual void put(JSObject*, ExecState*, PropertyName, JSValue, PutPropertySlot&);
@@ -117,20 +122,20 @@
         Weak<JSObject> m_reference;
     };
 
-    static PassRefPtr<QtInstance> create(QObject *instance, PassRefPtr<RootObject> rootObject, QScriptEngine::ValueOwnership ownership)
+    static PassRefPtr<QtInstance> create(QObject *instance, PassRefPtr<RootObject> rootObject, ValueOwnership ownership)
     {
         return adoptRef(new QtInstance(instance, rootObject, ownership));
     }
 
     friend class QtClass;
     friend class QtField;
-    QtInstance(QObject*, PassRefPtr<RootObject>, QScriptEngine::ValueOwnership ownership); // Factory produced only..
+    QtInstance(QObject*, PassRefPtr<RootObject>, ValueOwnership); // Factory produced only..
     mutable QtClass* m_class;
     QWeakPointer<QObject> m_object;
     QObject* m_hashkey;
     mutable QHash<QByteArray, QtWeakObjectReference> m_methods;
     mutable QHash<QString, QtField*> m_fields;
-    QScriptEngine::ValueOwnership m_ownership;
+    ValueOwnership m_ownership;
 };
 
 } // namespace Bindings

Modified: trunk/Source/WebCore/bridge/qt/qt_runtime.cpp (120195 => 120196)


--- trunk/Source/WebCore/bridge/qt/qt_runtime.cpp	2012-06-13 13:11:24 UTC (rev 120195)
+++ trunk/Source/WebCore/bridge/qt/qt_runtime.cpp	2012-06-13 13:37:54 UTC (rev 120196)
@@ -897,7 +897,7 @@
         QObject* obj = variant.value<QObject*>();
         if (!obj)
             return jsNull();
-        return QtInstance::getQtInstance(obj, root, QScriptEngine::QtOwnership)->createRuntimeObject(exec);
+        return QtInstance::getQtInstance(obj, root, QtInstance::QtOwnership)->createRuntimeObject(exec);
     }
 
     if (QtPixmapInstance::canHandle(static_cast<QMetaType::Type>(variant.type())))

Modified: trunk/Source/WebCore/bridge/qt/qt_runtime_qt4.cpp (120195 => 120196)


--- trunk/Source/WebCore/bridge/qt/qt_runtime_qt4.cpp	2012-06-13 13:11:24 UTC (rev 120195)
+++ trunk/Source/WebCore/bridge/qt/qt_runtime_qt4.cpp	2012-06-13 13:37:54 UTC (rev 120196)
@@ -897,7 +897,7 @@
         QObject* obj = variant.value<QObject*>();
         if (!obj)
             return jsNull();
-        return QtInstance::getQtInstance(obj, root, QScriptEngine::QtOwnership)->createRuntimeObject(exec);
+        return QtInstance::getQtInstance(obj, root, QtInstance::QtOwnership)->createRuntimeObject(exec);
     }
 
     if (QtPixmapInstance::canHandle(static_cast<QMetaType::Type>(variant.type())))

Modified: trunk/Source/WebKit/qt/Api/qwebframe.cpp (120195 => 120196)


--- trunk/Source/WebKit/qt/Api/qwebframe.cpp	2012-06-13 13:11:24 UTC (rev 120195)
+++ trunk/Source/WebKit/qt/Api/qwebframe.cpp	2012-06-13 13:37:54 UTC (rev 120196)
@@ -500,7 +500,7 @@
 
     JSC::ExecState* exec = ::toJS(context);
     RefPtr<JSC::Bindings::RootObject> rootObject = JSC::Bindings::findRootObject(exec->dynamicGlobalObject());
-    JSC::JSObject* jsSender = JSC::Bindings::QtInstance::getQtInstance(sender, rootObject, QScriptEngine::QtOwnership)->createRuntimeObject(exec);
+    JSC::JSObject* jsSender = JSC::Bindings::QtInstance::getQtInstance(sender, rootObject, JSC::Bindings::QtInstance::QtOwnership)->createRuntimeObject(exec);
     return ::toRef(jsSender);
 }
 
@@ -629,31 +629,8 @@
 }
 
 /*!
-    Make \a object available under \a name from within the frame's _javascript_
-    context. The \a object will be inserted as a child of the frame's window
-    object.
+    \fn void QWebFrame::addToJavaScriptWindowObject(const QString &name, QObject *object, ValueOwnership own)
 
-    Qt properties will be exposed as _javascript_ properties and slots as
-    _javascript_ methods.
-    The interaction between C++ and _javascript_ is explained in the documentation of the \l{The QtWebKit Bridge}{QtWebKit bridge}.
-
-    If you want to ensure that your QObjects remain accessible after loading a
-    new URL, you should add them in a slot connected to the
-    _javascript_WindowObjectCleared() signal.
-
-    If _javascript_ is not enabled for this page, then this method does nothing.
-
-    The \a object will never be explicitly deleted by QtWebKit.
-*/
-void QWebFrame::addToJavaScriptWindowObject(const QString &name, QObject *object)
-{
-    addToJavaScriptWindowObject(name, object, QScriptEngine::QtOwnership);
-}
-
-/*!
-    \fn void QWebFrame::addToJavaScriptWindowObject(const QString &name, QObject *object, QScriptEngine::ValueOwnership own)
-    \overload
-
     Make \a object available under \a name from within the frame's _javascript_
     context. The \a object will be inserted as a child of the frame's window
     object.
@@ -670,15 +647,20 @@
 
     The ownership of \a object is specified using \a own.
 */
+#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
+void QWebFrame::addToJavaScriptWindowObject(const QString &name, QObject *object, ValueOwnership ownership)
+#else
 void QWebFrame::addToJavaScriptWindowObject(const QString &name, QObject *object, QScriptEngine::ValueOwnership ownership)
+#endif
 {
     if (!page()->settings()->testAttribute(QWebSettings::_javascript_Enabled))
         return;
 #if USE(JSC)
+    JSC::Bindings::QtInstance::ValueOwnership valueOwnership = static_cast<JSC::Bindings::QtInstance::ValueOwnership>(ownership);
     JSC::JSLock lock(JSC::SilenceAssertionsOnly);
     JSDOMWindow* window = toJSDOMWindow(d->frame, mainThreadNormalWorld());
     JSC::Bindings::RootObject* root;
-    if (ownership == QScriptEngine::QtOwnership)
+    if (valueOwnership == JSC::Bindings::QtInstance::QtOwnership)
         root = d->frame->script()->cacheableBindingRootObject();
     else
         root = d->frame->script()->bindingRootObject();
@@ -695,7 +677,7 @@
     JSC::ExecState* exec = window->globalExec();
 
     JSC::JSObject* runtimeObject =
-            JSC::Bindings::QtInstance::getQtInstance(object, root, ownership)->createRuntimeObject(exec);
+            JSC::Bindings::QtInstance::getQtInstance(object, root, valueOwnership)->createRuntimeObject(exec);
 
     JSC::PutPropertySlot slot;
     window->methodTable()->put(window, exec, JSC::Identifier(&exec->globalData(), reinterpret_cast_ptr<const UChar*>(name.constData()), name.length()), runtimeObject, slot);

Modified: trunk/Source/WebKit/qt/Api/qwebframe.h (120195 => 120196)


--- trunk/Source/WebKit/qt/Api/qwebframe.h	2012-06-13 13:11:24 UTC (rev 120195)
+++ trunk/Source/WebKit/qt/Api/qwebframe.h	2012-06-13 13:37:54 UTC (rev 120196)
@@ -25,10 +25,13 @@
 #include <QtCore/qurl.h>
 #include <QtCore/qvariant.h>
 #include <QtGui/qicon.h>
-#include <QtScript/qscriptengine.h>
 #include <QtNetwork/qnetworkaccessmanager.h>
 #include "qwebkitglobal.h"
 
+#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
+#include <QtScript/qscriptengine.h>
+#endif
+
 QT_BEGIN_NAMESPACE
 class QRect;
 class QPoint;
@@ -121,6 +124,14 @@
     ~QWebFrame();
 
 public:
+#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
+    enum ValueOwnership {
+        QtOwnership,
+        ScriptOwnership,
+        AutoOwnership
+    };
+#endif
+
     QWebPage *page() const;
 
     void load(const QUrl &url);
@@ -128,8 +139,11 @@
     void setHtml(const QString &html, const QUrl &baseUrl = QUrl());
     void setContent(const QByteArray &data, const QString &mimeType = QString(), const QUrl &baseUrl = QUrl());
 
-    void addToJavaScriptWindowObject(const QString &name, QObject *object);
-    void addToJavaScriptWindowObject(const QString &name, QObject *object, QScriptEngine::ValueOwnership ownership);
+#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
+    void addToJavaScriptWindowObject(const QString &name, QObject *object, ValueOwnership ownership = QtOwnership);
+#else
+    void addToJavaScriptWindowObject(const QString &name, QObject *object, QScriptEngine::ValueOwnership ownership = QScriptEngine::QtOwnership);
+#endif
     QString toHtml() const;
     QString toPlainText() const;
     QString renderTreeDump() const;

Modified: trunk/Source/WebKit/qt/ChangeLog (120195 => 120196)


--- trunk/Source/WebKit/qt/ChangeLog	2012-06-13 13:11:24 UTC (rev 120195)
+++ trunk/Source/WebKit/qt/ChangeLog	2012-06-13 13:37:54 UTC (rev 120196)
@@ -1,3 +1,23 @@
+2012-06-13  Simon Hausmann  <[email protected]>
+
+        [Qt] Remove dependency to QtScript for the Qt 5 build
+        https://bugs.webkit.org/show_bug.cgi?id=88993
+
+        Reviewed by Kenneth Rohde Christiansen.
+
+        When building against Qt 5, replace the use of QScriptEngine::ValueOwnership with
+        a (compatible) QWebFrame::ValueOwnership enum.
+
+        * Api/qwebframe.cpp:
+        (qtSenderCallback):
+        (QWebFrame::addToJavaScriptWindowObject):
+        * Api/qwebframe.h:
+        * tests/qobjectbridge/tst_qobjectbridge.cpp:
+        (tst_QObjectBridge::arrayObjectEnumerable):
+        (tst_QObjectBridge::ownership):
+        (tst_QObjectBridge::qObjectWrapperWithSameIdentity):
+
+
 2012-06-12  Csaba Osztrogonác  <[email protected]>
 
         [Qt][Mac] Unreviewed buildfix after r120076.

Modified: trunk/Source/WebKit/qt/tests/qobjectbridge/tst_qobjectbridge.cpp (120195 => 120196)


--- trunk/Source/WebKit/qt/tests/qobjectbridge/tst_qobjectbridge.cpp	2012-06-13 13:11:24 UTC (rev 120195)
+++ trunk/Source/WebKit/qt/tests/qobjectbridge/tst_qobjectbridge.cpp	2012-06-13 13:37:54 UTC (rev 120196)
@@ -37,6 +37,12 @@
 Q_DECLARE_METATYPE(QVariantList)
 Q_DECLARE_METATYPE(QVariantMap)
 
+#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
+#define OwnershipClass QWebFrame
+#else
+#define OwnershipClass QScriptEngine
+#endif
+
 class MyQObject : public QObject {
     Q_OBJECT
 
@@ -1994,7 +2000,7 @@
     QWebPage page;
     QWebFrame* frame = page.mainFrame();
     QObject* qobject = new StringListTestObject();
-    frame->addToJavaScriptWindowObject("test", qobject, QScriptEngine::ScriptOwnership);
+    frame->addToJavaScriptWindowObject("test", qobject, OwnershipClass::ScriptOwnership);
 
     const QString script("var stringArray = test.stringList();"
                          "var result = '';"
@@ -2035,7 +2041,7 @@
         {
             QWebPage page;
             QWebFrame* frame = page.mainFrame();
-            frame->addToJavaScriptWindowObject("test", ptr.data(), QScriptEngine::ScriptOwnership);
+            frame->addToJavaScriptWindowObject("test", ptr.data(), OwnershipClass::ScriptOwnership);
         }
         QVERIFY(!ptr);
     }
@@ -2046,7 +2052,7 @@
         {
             QWebPage page;
             QWebFrame* frame = page.mainFrame();
-            frame->addToJavaScriptWindowObject("test", ptr.data(), QScriptEngine::QtOwnership);
+            frame->addToJavaScriptWindowObject("test", ptr.data(), OwnershipClass::QtOwnership);
         }
         QVERIFY(ptr.data() == before);
         delete ptr.data();
@@ -2056,7 +2062,7 @@
         QObject* child = new QObject(parent);
         QWebPage page;
         QWebFrame* frame = page.mainFrame();
-        frame->addToJavaScriptWindowObject("test", child, QScriptEngine::QtOwnership);
+        frame->addToJavaScriptWindowObject("test", child, OwnershipClass::QtOwnership);
         QVariant v = frame->evaluateJavaScript("test");
         QCOMPARE(qvariant_cast<QObject*>(v), child);
         delete parent;
@@ -2069,7 +2075,7 @@
         {
             QWebPage page;
             QWebFrame* frame = page.mainFrame();
-            frame->addToJavaScriptWindowObject("test", ptr.data(), QScriptEngine::AutoOwnership);
+            frame->addToJavaScriptWindowObject("test", ptr.data(), OwnershipClass::AutoOwnership);
         }
         // no parent, so it should be like ScriptOwnership
         QVERIFY(!ptr);
@@ -2081,7 +2087,7 @@
         {
             QWebPage page;
             QWebFrame* frame = page.mainFrame();
-            frame->addToJavaScriptWindowObject("test", child.data(), QScriptEngine::AutoOwnership);
+            frame->addToJavaScriptWindowObject("test", child.data(), OwnershipClass::AutoOwnership);
         }
         // has parent, so it should be like QtOwnership
         QVERIFY(child);
@@ -2123,7 +2129,7 @@
     QWebFrame* mainFrame = m_view->page()->mainFrame();
     QCOMPARE(mainFrame->toPlainText(), QString("test"));
 
-    mainFrame->addToJavaScriptWindowObject("test", new TestFactory, QScriptEngine::ScriptOwnership);
+    mainFrame->addToJavaScriptWindowObject("test", new TestFactory, OwnershipClass::ScriptOwnership);
 
     mainFrame->evaluateJavaScript("triggerBug();");
     QCOMPARE(mainFrame->toPlainText(), QString("test1"));
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to