Initial V8 integration
[profile/ivi/qtdeclarative.git] / src / declarative / qml / v8 / qv8qobjectwrapper_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** No Commercial Usage
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
14 ** this package.
15 **
16 ** GNU Lesser General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 ** General Public License version 2.1 as published by the Free Software
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 ** packaging of this file.  Please review the following information to
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23 **
24 ** In addition, as a special exception, Nokia gives you certain additional
25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
30 **
31 **
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef QV8QOBJECTWRAPPER_P_H
43 #define QV8QOBJECTWRAPPER_P_H
44
45 //
46 //  W A R N I N G
47 //  -------------
48 //
49 // This file is not part of the Qt API.  It exists purely as an
50 // implementation detail.  This header file may change from version to
51 // version without notice, or even be removed.
52 //
53 // We mean it.
54 //
55
56 #include <QtCore/qglobal.h>
57 #include <QtCore/qmetatype.h>
58 #include <QtCore/qpair.h>
59 #include <QtCore/qhash.h>
60 #include <private/qv8_p.h>
61
62 QT_BEGIN_NAMESPACE
63
64 class QObject;
65 class QV8Engine;
66 class QV8ObjectResource;
67 class QDeclarativePropertyCache;
68 class QV8QObjectConnectionList;
69 class Q_AUTOTEST_EXPORT QV8QObjectWrapper 
70 {
71 public:
72     QV8QObjectWrapper();
73     ~QV8QObjectWrapper();
74
75     void init(QV8Engine *);
76     void destroy();
77
78     v8::Handle<v8::Value> newQObject(QObject *object);
79     bool isQObject(v8::Handle<v8::Object>);
80     QObject *toQObject(v8::Handle<v8::Object>);
81     QObject *toQObject(QV8ObjectResource *);
82
83     enum RevisionMode { IgnoreRevision, CheckRevision };
84     v8::Handle<v8::Value> getProperty(QObject *, v8::Handle<v8::String>, RevisionMode);
85     bool setProperty(QObject *, v8::Handle<v8::String>, v8::Handle<v8::Value>, RevisionMode);
86
87 private:
88     friend class QDeclarativePropertyCache;
89     friend class QV8QObjectConnectionList;
90
91     static v8::Handle<v8::Value> GetProperty(QV8Engine *, QObject *, v8::Handle<v8::Value> *, 
92                                              v8::Handle<v8::String>, QV8QObjectWrapper::RevisionMode);
93     static bool SetProperty(QV8Engine *, QObject *, v8::Handle<v8::String>,
94                             v8::Handle<v8::Value>, QV8QObjectWrapper::RevisionMode);
95     static v8::Handle<v8::Value> Getter(v8::Local<v8::String> property, 
96                                         const v8::AccessorInfo &info);
97     static v8::Handle<v8::Value> Setter(v8::Local<v8::String> property, 
98                                         v8::Local<v8::Value> value,
99                                         const v8::AccessorInfo &info);
100     static v8::Handle<v8::Integer> Query(v8::Local<v8::String> property,
101                                          const v8::AccessorInfo &info);
102     static v8::Handle<v8::Array> Enumerator(const v8::AccessorInfo &info);
103     static v8::Handle<v8::Value> Connect(const v8::Arguments &args);
104     static v8::Handle<v8::Value> Disconnect(const v8::Arguments &args);
105     static v8::Handle<v8::Value> Invoke(const v8::Arguments &args);
106     static QPair<QObject *, int> ExtractQtMethod(QV8Engine *, v8::Handle<v8::Function>);
107
108     QV8Engine *m_engine;
109     v8::Persistent<v8::Function> m_constructor;
110     v8::Persistent<v8::Function> m_methodConstructor;
111     v8::Persistent<v8::String> m_toStringSymbol;
112     v8::Persistent<v8::String> m_destroySymbol;
113     v8::Persistent<v8::Object> m_hiddenObject;
114     QHash<QObject *, QV8QObjectConnectionList *> m_connections;
115 };
116
117 QT_END_NAMESPACE
118
119 #endif // QV8QOBJECTWRAPPER_P_H
120
121