~ubuntu-branches/ubuntu/wily/qtdeclarative-opensource-src/wily-proposed

« back to all changes in this revision

Viewing changes to src/qml/jsruntime/qv4managed_p.h

  • Committer: Package Import Robot
  • Author(s): Ricardo Salveti de Araujo, Ricardo Salveti de Araujo, Timo Jyrinki
  • Date: 2014-06-19 02:39:21 UTC
  • mfrom: (0.1.18 experimental)
  • Revision ID: package-import@ubuntu.com-20140619023921-yb2oasnuetz9b0fc
Tags: 5.3.0-3ubuntu4
[ Ricardo Salveti de Araujo ]
* debian/control:
  - Updating dependencies as we now also have libqt5quickwidgets5-gles
* libqt5quickwidgets5.symbols: updating to allow gles variant

[ Timo Jyrinki ]
* Update libqt5quickparticles5.symbols from build logs

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
#include <QtCore/QVector>
46
46
#include <QtCore/QDebug>
47
47
#include "qv4global_p.h"
48
 
#include "qv4value_def_p.h"
 
48
#include "qv4value_p.h"
49
49
#include "qv4internalclass_p.h"
50
50
 
51
51
QT_BEGIN_NAMESPACE
53
53
namespace QV4 {
54
54
 
55
55
#define Q_MANAGED_CHECK \
56
 
    template <typename T> inline void qt_check_for_QMANAGED_macro(const T &_q_argument) const \
57
 
    { int i = qYouForgotTheQ_MANAGED_Macro(this, &_q_argument); i = i + 1; }
 
56
    template <typename T> inline void qt_check_for_QMANAGED_macro(const T *_q_argument) const \
 
57
    { int i = qYouForgotTheQ_MANAGED_Macro(this, _q_argument); i = i + 1; }
58
58
 
59
59
template <typename T>
60
60
inline int qYouForgotTheQ_MANAGED_Macro(T, T) { return 0; }
62
62
template <typename T1, typename T2>
63
63
inline void qYouForgotTheQ_MANAGED_Macro(T1, T2) {}
64
64
 
65
 
#define Q_MANAGED \
 
65
#define V4_MANAGED \
66
66
    public: \
67
67
        Q_MANAGED_CHECK \
68
68
        static const QV4::ManagedVTable static_vtbl; \
69
 
        template <typename T> \
70
 
        QV4::Returned<T> *asReturned() { return QV4::Returned<T>::create(this); } \
71
 
 
 
69
        static inline const QV4::ManagedVTable *staticVTable() { return &static_vtbl; } \
 
70
        template <typename T> \
 
71
        QV4::Returned<T> *asReturned() { return QV4::Returned<T>::create(this); } \
 
72
 
 
73
#define V4_OBJECT \
 
74
    public: \
 
75
        Q_MANAGED_CHECK \
 
76
        static const QV4::ObjectVTable static_vtbl; \
 
77
        static inline const QV4::ManagedVTable *staticVTable() { return &static_vtbl.managedVTable; } \
 
78
        template <typename T> \
 
79
        QV4::Returned<T> *asReturned() { return QV4::Returned<T>::create(this); } \
 
80
 
 
81
#define Q_MANAGED_TYPE(type) \
 
82
    public: \
 
83
        enum { MyType = Type_##type };
72
84
 
73
85
struct GCDeletable
74
86
{
80
92
 
81
93
struct ManagedVTable
82
94
{
 
95
    uint isExecutionContext : 1;
 
96
    uint isString : 1;
 
97
    uint isObject : 1;
 
98
    uint isFunctionObject : 1;
 
99
    uint isErrorObject : 1;
 
100
    uint isArrayData : 1;
 
101
    uint unused : 18;
 
102
    uint type : 8;
 
103
    const char *className;
 
104
    void (*destroy)(Managed *);
 
105
    void (*markObjects)(Managed *, ExecutionEngine *e);
 
106
    bool (*isEqualTo)(Managed *m, Managed *other);
 
107
};
 
108
 
 
109
struct ObjectVTable
 
110
{
 
111
    ManagedVTable managedVTable;
83
112
    ReturnedValue (*call)(Managed *, CallData *data);
84
113
    ReturnedValue (*construct)(Managed *, CallData *data);
85
 
    void (*markObjects)(Managed *, ExecutionEngine *e);
86
 
    void (*destroy)(Managed *);
87
 
    void (*collectDeletables)(Managed *, GCDeletable **deletable);
88
114
    ReturnedValue (*get)(Managed *, const StringRef name, bool *hasProperty);
89
115
    ReturnedValue (*getIndexed)(Managed *, uint index, bool *hasProperty);
90
116
    void (*put)(Managed *, const StringRef name, const ValueRef value);
95
121
    bool (*deleteIndexedProperty)(Managed *m, uint index);
96
122
    ReturnedValue (*getLookup)(Managed *m, Lookup *l);
97
123
    void (*setLookup)(Managed *m, Lookup *l, const ValueRef v);
98
 
    bool (*isEqualTo)(Managed *m, Managed *other);
99
 
    Property *(*advanceIterator)(Managed *m, ObjectIterator *it, StringRef name, uint *index, PropertyAttributes *attributes);
100
 
    const char *className;
 
124
    uint (*getLength)(const Managed *m);
 
125
    void (*advanceIterator)(Managed *m, ObjectIterator *it, StringRef name, uint *index, Property *p, PropertyAttributes *attributes);
101
126
};
102
127
 
 
128
#define DEFINE_MANAGED_VTABLE_INT(classname) \
 
129
{     \
 
130
    classname::IsExecutionContext,   \
 
131
    classname::IsString,   \
 
132
    classname::IsObject,   \
 
133
    classname::IsFunctionObject,   \
 
134
    classname::IsErrorObject,   \
 
135
    classname::IsArrayData,   \
 
136
    0,                                          \
 
137
    classname::MyType,                          \
 
138
    #classname,                                 \
 
139
    destroy,                                    \
 
140
    markObjects,                                \
 
141
    isEqualTo                                  \
 
142
}
 
143
 
 
144
 
103
145
#define DEFINE_MANAGED_VTABLE(classname) \
104
 
const QV4::ManagedVTable classname::static_vtbl =    \
105
 
{                                               \
106
 
    call,                                       \
107
 
    construct,                                  \
108
 
    markObjects,                                \
109
 
    destroy,                                    \
110
 
    0,                                          \
111
 
    get,                                        \
112
 
    getIndexed,                                 \
113
 
    put,                                        \
114
 
    putIndexed,                                 \
115
 
    query,                                      \
116
 
    queryIndexed,                               \
117
 
    deleteProperty,                             \
118
 
    deleteIndexedProperty,                      \
119
 
    getLookup,                                  \
120
 
    setLookup,                                  \
121
 
    isEqualTo,                                  \
122
 
    advanceIterator,                            \
123
 
    #classname                                  \
124
 
}
125
 
 
126
 
#define DEFINE_MANAGED_VTABLE_WITH_DELETABLES(classname) \
127
 
const QV4::ManagedVTable classname::static_vtbl =    \
128
 
{                                               \
129
 
    call,                                       \
130
 
    construct,                                  \
131
 
    markObjects,                                \
132
 
    destroy,                                    \
133
 
    collectDeletables,                          \
134
 
    get,                                        \
135
 
    getIndexed,                                 \
136
 
    put,                                        \
137
 
    putIndexed,                                 \
138
 
    query,                                      \
139
 
    queryIndexed,                               \
140
 
    deleteProperty,                             \
141
 
    deleteIndexedProperty,                      \
142
 
    getLookup,                                  \
143
 
    setLookup,                                  \
144
 
    isEqualTo,                                  \
145
 
    advanceIterator,                            \
146
 
    #classname                                  \
147
 
}
148
 
 
149
 
struct Q_QML_EXPORT Managed
 
146
const QV4::ManagedVTable classname::static_vtbl = DEFINE_MANAGED_VTABLE_INT(classname)
 
147
 
 
148
 
 
149
#define DEFINE_OBJECT_VTABLE(classname) \
 
150
const QV4::ObjectVTable classname::static_vtbl =    \
 
151
{     \
 
152
    DEFINE_MANAGED_VTABLE_INT(classname), \
 
153
    call,                                       \
 
154
    construct,                                  \
 
155
    get,                                        \
 
156
    getIndexed,                                 \
 
157
    put,                                        \
 
158
    putIndexed,                                 \
 
159
    query,                                      \
 
160
    queryIndexed,                               \
 
161
    deleteProperty,                             \
 
162
    deleteIndexedProperty,                      \
 
163
    getLookup,                                  \
 
164
    setLookup,                                  \
 
165
    getLength,                                  \
 
166
    advanceIterator                            \
 
167
}
 
168
 
 
169
#define DEFINE_MANAGED_VTABLE_WITH_NAME(classname, name) \
 
170
const QV4::ObjectVTable classname::static_vtbl =    \
 
171
{                                               \
 
172
    DEFINE_MANAGED_VTABLE_INT(name), \
 
173
    call,                                       \
 
174
    construct,                                  \
 
175
    get,                                        \
 
176
    getIndexed,                                 \
 
177
    put,                                        \
 
178
    putIndexed,                                 \
 
179
    query,                                      \
 
180
    queryIndexed,                               \
 
181
    deleteProperty,                             \
 
182
    deleteIndexedProperty,                      \
 
183
    getLookup,                                  \
 
184
    setLookup,                                  \
 
185
    getLength,                                  \
 
186
    advanceIterator                            \
 
187
}
 
188
 
 
189
 
 
190
struct Q_QML_PRIVATE_EXPORT Managed
150
191
{
151
 
    Q_MANAGED
 
192
    V4_MANAGED
 
193
    enum {
 
194
        IsExecutionContext = false,
 
195
        IsString = false,
 
196
        IsObject = false,
 
197
        IsFunctionObject = false,
 
198
        IsErrorObject = false,
 
199
        IsArrayData = false
 
200
    };
152
201
private:
153
202
    void *operator new(size_t);
154
203
    Managed(const Managed &other);
158
207
    Managed(InternalClass *internal)
159
208
        : internalClass(internal), _data(0)
160
209
    {
161
 
        Q_ASSERT(!internalClass || internalClass->vtable);
 
210
        Q_ASSERT(internalClass && internalClass->vtable);
162
211
        inUse = 1; extensible = 1;
163
212
    }
164
213
 
183
232
        Type_RegExpObject,
184
233
        Type_ErrorObject,
185
234
        Type_ArgumentsObject,
186
 
        Type_JSONObject,
 
235
        Type_JsonObject,
187
236
        Type_MathObject,
 
237
 
 
238
        Type_ExecutionContext,
188
239
        Type_ForeachIteratorObject,
189
240
        Type_RegExp,
190
241
 
191
242
        Type_QmlSequence
192
243
    };
 
244
    Q_MANAGED_TYPE(Invalid)
193
245
 
194
246
    ExecutionEngine *engine() const;
195
247
 
199
251
        if (!this || !internalClass)
200
252
            return 0;
201
253
#if !defined(QT_NO_QOBJECT_CHECK)
202
 
        static_cast<T *>(this)->qt_check_for_QMANAGED_macro(*static_cast<T *>(this));
 
254
        static_cast<T *>(this)->qt_check_for_QMANAGED_macro(static_cast<T *>(this));
203
255
#endif
204
 
        return internalClass->vtable == &T::static_vtbl ? static_cast<T *>(this) : 0;
 
256
        return internalClass->vtable == T::staticVTable() ? static_cast<T *>(this) : 0;
205
257
    }
206
258
    template <typename T>
207
259
    const T *as() const {
209
261
        if (!this)
210
262
            return 0;
211
263
#if !defined(QT_NO_QOBJECT_CHECK)
212
 
        reinterpret_cast<T *>(this)->qt_check_for_QMANAGED_macro(*reinterpret_cast<T *>(const_cast<Managed *>(this)));
 
264
        static_cast<T *>(this)->qt_check_for_QMANAGED_macro(static_cast<T *>(const_cast<Managed *>(this)));
213
265
#endif
214
 
        return internalClass->vtable == &T::static_vtbl ? static_cast<const T *>(this) : 0;
 
266
        return internalClass->vtable == T::staticVTable() ? static_cast<const T *>(this) : 0;
215
267
    }
216
268
 
217
 
    String *asString() { return type == Type_String ? reinterpret_cast<String *>(this) : 0; }
218
 
    Object *asObject() { return type != Type_String ? reinterpret_cast<Object *>(this) : 0; }
219
 
    ArrayObject *asArrayObject() { return type == Type_ArrayObject ? reinterpret_cast<ArrayObject *>(this) : 0; }
220
 
    FunctionObject *asFunctionObject() { return type == Type_FunctionObject ? reinterpret_cast<FunctionObject *>(this) : 0; }
221
 
    BooleanObject *asBooleanObject() { return type == Type_BooleanObject ? reinterpret_cast<BooleanObject *>(this) : 0; }
222
 
    NumberObject *asNumberObject() { return type == Type_NumberObject ? reinterpret_cast<NumberObject *>(this) : 0; }
223
 
    StringObject *asStringObject() { return type == Type_StringObject ? reinterpret_cast<StringObject *>(this) : 0; }
224
 
    DateObject *asDateObject() { return type == Type_DateObject ? reinterpret_cast<DateObject *>(this) : 0; }
225
 
    ErrorObject *asErrorObject() { return type == Type_ErrorObject ? reinterpret_cast<ErrorObject *>(this) : 0; }
226
 
    ArgumentsObject *asArgumentsObject() { return type == Type_ArgumentsObject ? reinterpret_cast<ArgumentsObject *>(this) : 0; }
227
 
 
228
 
    bool isListType() const { return type == Type_QmlSequence; }
229
 
 
230
 
    bool isArrayObject() const { return type == Type_ArrayObject; }
231
 
    bool isStringObject() const { return type == Type_StringObject; }
 
269
    String *asString() { return internalClass->vtable->isString ? reinterpret_cast<String *>(this) : 0; }
 
270
    Object *asObject() { return internalClass->vtable->isObject ? reinterpret_cast<Object *>(this) : 0; }
 
271
    ArrayObject *asArrayObject() { return internalClass->vtable->type == Type_ArrayObject ? reinterpret_cast<ArrayObject *>(this) : 0; }
 
272
    FunctionObject *asFunctionObject() { return internalClass->vtable->isFunctionObject ? reinterpret_cast<FunctionObject *>(this) : 0; }
 
273
    BooleanObject *asBooleanObject() { return internalClass->vtable->type == Type_BooleanObject ? reinterpret_cast<BooleanObject *>(this) : 0; }
 
274
    NumberObject *asNumberObject() { return internalClass->vtable->type == Type_NumberObject ? reinterpret_cast<NumberObject *>(this) : 0; }
 
275
    StringObject *asStringObject() { return internalClass->vtable->type == Type_StringObject ? reinterpret_cast<StringObject *>(this) : 0; }
 
276
    DateObject *asDateObject() { return internalClass->vtable->type == Type_DateObject ? reinterpret_cast<DateObject *>(this) : 0; }
 
277
    ErrorObject *asErrorObject() { return internalClass->vtable->isErrorObject ? reinterpret_cast<ErrorObject *>(this) : 0; }
 
278
    ArgumentsObject *asArgumentsObject() { return internalClass->vtable->type == Type_ArgumentsObject ? reinterpret_cast<ArgumentsObject *>(this) : 0; }
 
279
 
 
280
    bool isListType() const { return internalClass->vtable->type == Type_QmlSequence; }
 
281
 
 
282
    bool isArrayObject() const { return internalClass->vtable->type == Type_ArrayObject; }
 
283
    bool isStringObject() const { return internalClass->vtable->type == Type_StringObject; }
232
284
 
233
285
    QString className() const;
234
286
 
244
296
 
245
297
    void setVTable(const ManagedVTable *vt);
246
298
 
247
 
    ReturnedValue construct(CallData *d);
248
 
    ReturnedValue call(CallData *d);
249
 
    ReturnedValue get(const StringRef name, bool *hasProperty = 0);
250
 
    ReturnedValue getIndexed(uint index, bool *hasProperty = 0);
251
 
    void put(const StringRef name, const ValueRef value);
252
 
    void putIndexed(uint index, const ValueRef value);
253
 
    PropertyAttributes query(StringRef name) const;
254
 
    PropertyAttributes queryIndexed(uint index) const
255
 
    { return internalClass->vtable->queryIndexed(this, index); }
256
 
 
257
 
    bool deleteProperty(const StringRef name);
258
 
    bool deleteIndexedProperty(uint index)
259
 
    { return internalClass->vtable->deleteIndexedProperty(this, index); }
260
 
    ReturnedValue getLookup(Lookup *l)
261
 
    { return internalClass->vtable->getLookup(this, l); }
262
 
    void setLookup(Lookup *l, const ValueRef v);
263
 
 
264
299
    bool isEqualTo(Managed *other)
265
300
    { return internalClass->vtable->isEqualTo(this, other); }
266
 
    Property *advanceIterator(ObjectIterator *it, StringRef name, uint *index, PropertyAttributes *attributes);
267
301
 
268
302
    static void destroy(Managed *that) { that->_data = 0; }
269
 
    static ReturnedValue construct(Managed *m, CallData *d);
270
 
    static ReturnedValue call(Managed *m, CallData *);
271
 
    static ReturnedValue getLookup(Managed *m, Lookup *);
272
 
    static void setLookup(Managed *m, Lookup *l, const ValueRef v);
273
303
    static bool isEqualTo(Managed *m, Managed *other);
274
304
 
275
 
    uint internalType() const {
276
 
        return type;
277
 
    }
278
 
 
279
305
    ReturnedValue asReturnedValue() { return Value::fromManaged(this).asReturnedValue(); }
280
306
 
281
307
 
282
308
    InternalClass *internalClass;
283
309
 
284
 
    enum {
285
 
        SimpleArray = 1
286
 
    };
287
 
 
288
310
    union {
289
311
        uint _data;
290
312
        struct {
291
313
            uchar markBit :  1;
292
314
            uchar inUse   :  1;
293
315
            uchar extensible : 1; // used by Object
294
 
            uchar isNonStrictArgumentsObject : 1;
 
316
            uchar _unused : 1;
295
317
            uchar needsActivation : 1; // used by FunctionObject
296
318
            uchar strictMode : 1; // used by FunctionObject
297
319
            uchar bindingKeyFlag : 1;
298
320
            uchar hasAccessorProperty : 1;
299
 
            uchar type;
 
321
            uchar _type;
300
322
            mutable uchar subtype;
301
 
            uchar flags;
 
323
            uchar _flags;
302
324
        };
303
325
    };
304
326
 
308
330
    friend struct ObjectIterator;
309
331
};
310
332
 
 
333
 
311
334
template<>
312
335
inline Managed *value_cast(const Value &v) {
313
336
    return v.asManaged();
336
359
}
337
360
 
338
361
 
339
 
inline ReturnedValue Managed::construct(CallData *d) {
340
 
    return internalClass->vtable->construct(this, d);
341
 
}
342
 
inline ReturnedValue Managed::call(CallData *d) {
343
 
    return internalClass->vtable->call(this, d);
344
 
}
 
362
Value *extractValuePointer(const ScopedValue &);
 
363
template<typename T>
 
364
Value *extractValuePointer(const Scoped<T> &);
 
365
 
 
366
#define DEFINE_REF_METHODS(Class, Base) \
 
367
    Class##Ref(const QV4::ScopedValue &v) \
 
368
    { QV4::Value *val = extractValuePointer(v); ptr = QV4::value_cast<Class>(*val) ? val : 0; } \
 
369
    Class##Ref(const QV4::Scoped<Class> &v) { ptr = extractValuePointer(v); } \
 
370
    Class##Ref(QV4::TypedValue<Class> &v) { ptr = &v; } \
 
371
    Class##Ref(QV4::Value &v) { ptr = QV4::value_cast<Class>(v) ? &v : 0; } \
 
372
    Class##Ref &operator=(Class *t) { \
 
373
        if (sizeof(void *) == 4) \
 
374
            ptr->tag = QV4::Value::Managed_Type; \
 
375
        ptr->m = t; \
 
376
        return *this; \
 
377
    } \
 
378
    Class##Ref &operator=(QV4::Returned<Class> *t) { \
 
379
        if (sizeof(void *) == 4) \
 
380
            ptr->tag = QV4::Value::Managed_Type; \
 
381
        ptr->m = t->getPointer(); \
 
382
        return *this; \
 
383
    } \
 
384
    operator const Class *() const { return ptr ? static_cast<Class*>(ptr->managed()) : 0; } \
 
385
    const Class *operator->() const { return static_cast<Class*>(ptr->managed()); } \
 
386
    operator Class *() { return ptr ? static_cast<Class*>(ptr->managed()) : 0; } \
 
387
    Class *operator->() { return static_cast<Class*>(ptr->managed()); } \
 
388
    Class *getPointer() const { return static_cast<Class *>(ptr->managed()); } \
 
389
    operator QV4::Returned<Class> *() const { return ptr ? QV4::Returned<Class>::create(getPointer()) : 0; } \
 
390
    static Class##Ref null() { Class##Ref c; c.ptr = 0; return c; } \
 
391
protected: \
 
392
    Class##Ref() {} \
 
393
public: \
 
394
 
 
395
#define DEFINE_REF(Class, Base) \
 
396
struct Class##Ref : public Base##Ref \
 
397
{ DEFINE_REF_METHODS(Class, Base) } \
 
398
 
 
399
 
 
400
struct ManagedRef {
 
401
    // Important: Do NOT add a copy constructor to this class or any derived class
 
402
    // adding a copy constructor actually changes the calling convention, ie.
 
403
    // is not even binary compatible. Adding it would break assumptions made
 
404
    // in the jit'ed code.
 
405
    DEFINE_REF_METHODS(Managed, Managed);
 
406
 
 
407
    bool operator==(const ManagedRef &other) {
 
408
        if (ptr == other.ptr)
 
409
            return true;
 
410
        return ptr && other.ptr && ptr->m == other.ptr->m;
 
411
    }
 
412
    bool operator!=(const ManagedRef &other) {
 
413
        return !operator==(other);
 
414
    }
 
415
    bool operator!() const { return !ptr || !ptr->managed(); }
 
416
 
 
417
    bool isNull() const { return !ptr; }
 
418
    ReturnedValue asReturnedValue() const { return ptr ? ptr->val : Primitive::undefinedValue().asReturnedValue(); }
 
419
 
 
420
public:
 
421
    Value *ptr;
 
422
};
345
423
 
346
424
}
347
425