1 /****************************************************************************
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
6 ** This file is part of the QtQml module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
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 *const**storeJumpTable = 0
138 v8::Persistent<v8::Object> run(QQmlContextData *, QQmlScriptData *);
140 #ifdef QML_THREADED_VME_INTERPRETER
141 static void *const*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