1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtQml module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
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.
56 #include "qqmlerror.h"
57 #include <private/qbitfield_p.h>
58 #include "qqmlinstruction_p.h"
59 #include <private/qrecursionwatcher_p.h>
61 #include <QtCore/QStack>
62 #include <QtCore/QString>
63 #include <QtCore/qelapsedtimer.h>
64 #include <QtCore/qcoreapplication.h>
66 #include <private/qv8_p.h>
67 #include <private/qqmlengine_p.h>
68 #include <private/qfinitestack_p.h>
70 #include <private/qqmltrace_p.h>
77 class QQmlCompiledData;
78 class QQmlCompiledData;
79 class QQmlContextData;
81 namespace QQmlVMETypes {
85 List(int t) : type(t) {}
88 QQmlListProperty<void> qListProperty;
91 Q_DECLARE_TYPEINFO(QQmlVMETypes::List, Q_PRIMITIVE_TYPE | Q_MOVABLE_TYPE);
93 class Q_QML_PRIVATE_EXPORT QQmlVME
95 Q_DECLARE_TR_FUNCTIONS(QQmlVME)
100 inline Interrupt(volatile bool *runWhile, int nsecs=0);
101 inline Interrupt(int nsecs);
104 inline bool shouldInterrupt() const;
106 enum Mode { None, Time, Flag };
112 volatile bool *runWhile;
115 QQmlVME() : data(0), componentAttached(0) {}
116 QQmlVME(void *data) : data(data), componentAttached(0) {}
119 QQmlComponentAttached *componentAttached;
120 QList<QQmlEnginePrivate::FinalizeCallback> finalizeCallbacks;
122 void init(QQmlContextData *, QQmlCompiledData *, int start,
123 QQmlContextData * = 0);
124 bool initDeferred(QObject *);
127 QObject *execute(QList<QQmlError> *errors, const Interrupt & = Interrupt());
128 QQmlContextData *complete(const Interrupt & = Interrupt());
131 friend class QQmlVMEGuard;
133 QObject *run(QList<QQmlError> *errors, const Interrupt &
134 #ifdef QML_THREADED_VME_INTERPRETER
135 , void ***storeJumpTable = 0
138 v8::Persistent<v8::Object> run(QQmlContextData *, QQmlScriptData *);
140 #ifdef QML_THREADED_VME_INTERPRETER
141 static void **instructionJumpTable();
142 friend class QQmlCompiledData;
146 QRecursionNode recursion;
148 #ifdef QML_ENABLE_TRACE
149 QQmlCompiledData *rootComponent;
152 QFiniteStack<QObject *> objects;
153 QFiniteStack<QQmlVMETypes::List> lists;
155 QFiniteStack<QQmlAbstractBinding *> bindValues;
156 QFiniteStack<QQmlParserStatus *> parserStatus;
157 #ifdef QML_ENABLE_TRACE
158 QFiniteStack<QQmlData *> parserStatusData;
161 QQmlGuardedContextData rootContext;
162 QQmlGuardedContextData creationContext;
165 enum Flag { Deferred = 0x00000001 };
167 State() : flags(0), context(0), compiledData(0), instructionStream(0) {}
169 QQmlContextData *context;
170 QQmlCompiledData *compiledData;
171 const char *instructionStream;
172 QBitField bindingSkipList;
175 QStack<State> states;
177 static void blank(QFiniteStack<QQmlParserStatus *> &);
178 static void blank(QFiniteStack<QQmlAbstractBinding *> &);
181 // Used to check that a QQmlVME that is interrupted mid-execution
182 // is still valid. Checks all the objects and contexts have not been
190 void guard(QQmlVME *);
197 QQmlGuard<QObject> *m_objects;
199 QQmlGuardedContextData *m_contexts;
202 QQmlVME::Interrupt::Interrupt()
203 : mode(None), nsecs(0), runWhile(0)
207 QQmlVME::Interrupt::Interrupt(volatile bool *runWhile, int nsecs)
208 : mode(Flag), nsecs(nsecs), runWhile(runWhile)
212 QQmlVME::Interrupt::Interrupt(int nsecs)
213 : mode(Time), nsecs(nsecs), runWhile(0)
217 void QQmlVME::Interrupt::reset()
219 if (mode == Time || nsecs)
223 bool QQmlVME::Interrupt::shouldInterrupt() const
227 } else if (mode == Time) {
228 return timer.nsecsElapsed() > nsecs;
229 } else if (mode == Flag) {
230 return !*runWhile || (nsecs && timer.nsecsElapsed() > nsecs);
238 #endif // QQMLVME_P_H