137 Q_DECLARE_TR_FUNCTIONS(QQmlObjectCreator)
139 enum class InitFlag: quint8
142 IsDocumentRoot = 0x1,
143 IsContextObject = 0x2,
148 const QQmlRefPointer<QV4::ExecutableCompilationUnit> &compilationUnit,
149 const QQmlRefPointer<QQmlContextData> &creationContext,
150 const QString &inlineComponentName,
152 ~QQmlObjectCreator();
155 QObject *
create(
int subComponentIndex = -1, QObject *parent =
nullptr,
162 const QV4::CompiledData::Binding *binding);
164 int index, QObject *instance, QObject *bindingTarget,
166 const QV4::CompiledData::Binding *binding =
nullptr);
179 return parentContext.contextData();
187 QQmlEngine *engine,
QV4::ExecutableCompilationUnit *compilationUnit,
int index,
188 QObject *parent,
const QQmlRefPointer<QQmlContextData> &context);
192 QList<DeferredQPropertyBinding> &pendingBindings = sharedState.data()->allQPropertyBindings;
194 return deferred.properyIndex == propertyIndex && deferred.target == target;
200 const QQmlRefPointer<QQmlContextData> &contextData,
201 const QQmlRefPointer<QV4::ExecutableCompilationUnit> &compilationUnit,
202 const QString inlineComponentName,
203 QQmlObjectCreatorSharedState *inheritedSharedState,
bool isContextObject);
205 void init(
const QQmlRefPointer<QQmlContextData> &parentContext);
207 void initializeDData(
208 const QV4::CompiledData::Object *obj, QObject *instance, QQmlData *ddata,
210 void initializePropertyCache(
211 int index, QQmlData *ddata,
const QV4::ResolvedTypeReference *typeRef);
212 void initializeParent(QObject *instance, QObject *parent);
213 QObject *populateInstanceAndAliasBindings(
int index, QObject *instance, InitFlags flags);
215 QObject *createInstance(
int index, QObject *parent =
nullptr,
bool isContextObject =
false);
217 QObject *initializeComponent(
218 const QV4::CompiledData::Object *obj, QObject *instance, InitFlags flags);
219 QObject *initializeComposite(
220 int index,
const QV4::CompiledData::Object *obj,
221 const QV4::ResolvedTypeReference *typeRef, QObject *instance, QObject *parent,
223 QObject *initializeNonComposite(
224 int index,
const QV4::CompiledData::Object *obj,
225 const QV4::ResolvedTypeReference *typeRef, QObject *instance, QObject *parent,
228 bool populateInstance(
int index, QObject *instance, QObject *bindingTarget,
230 const QV4::CompiledData::Binding *binding =
nullptr);
233 void populateDeferred(QObject *instance,
int deferredIndex);
234 void populateDeferred(QObject *instance,
int deferredIndex,
235 const QQmlPropertyPrivate *qmlProperty,
236 const QV4::CompiledData::Binding *binding);
240 ApplyImmediate = 0x1,
242 ApplyAll = ApplyImmediate | ApplyDeferred,
244 Q_DECLARE_FLAGS(BindingSetupFlags, BindingMode);
246 void setupBindings(BindingSetupFlags mode = BindingMode::ApplyImmediate);
247 bool setPropertyBinding(
const QQmlPropertyData *property,
const QV4::CompiledData::Binding *binding);
248 void setPropertyValue(
const QQmlPropertyData *property,
const QV4::CompiledData::Binding *binding);
249 void setupFunctions();
251 QString stringAt(
int idx)
const {
return compilationUnit->stringAt(idx); }
252 void recordError(
const QV4::CompiledData::Location &location,
const QString &description);
254 void registerObjectWithContextById(
const QV4::CompiledData::Object *object, QObject *instance)
const;
256 inline QV4::QmlContext *currentQmlContext();
257 QV4::ResolvedTypeReference *resolvedType(
int id)
const
259 return compilationUnit->resolvedType(id);
265 CreatingObjectsPhase2,
272 QV4::ExecutionEngine *v4;
273 QString m_inlineComponentName;
274 QQmlRefPointer<QV4::ExecutableCompilationUnit> compilationUnit;
275 const QV4::CompiledData::Unit *qmlUnit;
276 QQmlGuardedContextData parentContext;
277 QQmlRefPointer<QQmlContextData> context;
278 const QQmlPropertyCacheVector *propertyCaches;
279 QQmlRefPointer<QQmlObjectCreatorSharedState> sharedState;
280 bool topLevelCreator;
281 bool isContextObject;
285 QObject *_scopeObject;
286 QObject *_bindingTarget;
289 int _compiledObjectIndex;
290 const QV4::CompiledData::Object *_compiledObject;
292 QQmlPropertyCache::ConstPtr _propertyCache;
293 QQmlVMEMetaObject *_vmeMetaObject;
294 QQmlListProperty<QObject> _currentList;
295 QV4::QmlContext *_qmlContext;
299 typedef std::function<
bool(QQmlObjectCreatorSharedState *sharedState)> PendingAliasBinding;
300 std::vector<PendingAliasBinding> pendingAliasBindings;
302 template<
typename Functor>
303 void doPopulateDeferred(QObject *instance,
int deferredIndex, Functor f)
305 QQmlData *declarativeData = QQmlData::get(instance);
308 Q_ASSERT(declarativeData && declarativeData->propertyCache);
310 QObject *bindingTarget = instance;
312 QQmlPropertyCache::ConstPtr cache = declarativeData->propertyCache;
313 QQmlVMEMetaObject *vmeMetaObject = QQmlVMEMetaObject::get(instance);
315 QObject *scopeObject = instance;
316 qt_ptr_swap(_scopeObject, scopeObject);
318 QV4::Scope valueScope(v4);
319 QScopedValueRollback<ObjectInCreationGCAnchorList> jsObjectGuard(
320 sharedState->allJavaScriptObjects, ObjectInCreationGCAnchorList(valueScope));
322 Q_ASSERT(topLevelCreator);
323 QV4::QmlContext *qmlContext =
static_cast<QV4::QmlContext *>(valueScope.constructUndefined(1));
325 qt_ptr_swap(_qmlContext, qmlContext);
327 _propertyCache.swap(cache);
328 qt_ptr_swap(_qobject, instance);
330 int objectIndex = deferredIndex;
331 std::swap(_compiledObjectIndex, objectIndex);
333 const QV4::CompiledData::Object *obj = compilationUnit->objectAt(_compiledObjectIndex);
334 qt_ptr_swap(_compiledObject, obj);
335 qt_ptr_swap(_ddata, declarativeData);
336 qt_ptr_swap(_bindingTarget, bindingTarget);
337 qt_ptr_swap(_vmeMetaObject, vmeMetaObject);
341 qt_ptr_swap(_vmeMetaObject, vmeMetaObject);
342 qt_ptr_swap(_bindingTarget, bindingTarget);
343 qt_ptr_swap(_ddata, declarativeData);
344 qt_ptr_swap(_compiledObject, obj);
345 std::swap(_compiledObjectIndex, objectIndex);
346 qt_ptr_swap(_qobject, instance);
347 _propertyCache.swap(cache);
349 qt_ptr_swap(_qmlContext, qmlContext);
350 qt_ptr_swap(_scopeObject, scopeObject);
352 void registerPostHocRequiredProperties(
const QV4::CompiledData::Binding *binding);