139 Q_DECLARE_TR_FUNCTIONS(QQmlObjectCreator)
141 enum class InitFlag: quint8
144 IsDocumentRoot = 0x1,
145 IsContextObject = 0x2,
150 const QQmlRefPointer<QV4::ExecutableCompilationUnit> &compilationUnit,
151 const QQmlRefPointer<QQmlContextData> &creationContext,
152 const QString &inlineComponentName,
154 ~QQmlObjectCreator();
157 QObject *
create(
int subComponentIndex = -1, QObject *parent =
nullptr,
164 const QV4::CompiledData::Binding *binding);
166 int index, QObject *instance, QObject *bindingTarget,
168 const QV4::CompiledData::Binding *binding =
nullptr);
181 return parentContext.contextData();
189 QQmlEngine *engine,
QV4::ExecutableCompilationUnit *compilationUnit,
int index,
190 QObject *parent,
const QQmlRefPointer<QQmlContextData> &context);
194 QList<DeferredQPropertyBinding> &pendingBindings = sharedState.data()->allQPropertyBindings;
196 return deferred.properyIndex == propertyIndex && deferred.target == target;
202 const QQmlRefPointer<QQmlContextData> &contextData,
203 const QQmlRefPointer<QV4::ExecutableCompilationUnit> &compilationUnit,
204 const QString inlineComponentName,
205 QQmlObjectCreatorSharedState *inheritedSharedState,
bool isContextObject);
207 void init(
const QQmlRefPointer<QQmlContextData> &parentContext);
209 void initializeDData(
210 const QV4::CompiledData::Object *obj, QObject *instance, QQmlData *ddata,
212 void initializePropertyCache(
213 int index, QQmlData *ddata,
const QV4::ResolvedTypeReference *typeRef);
214 void initializeParent(QObject *instance, QObject *parent);
215 QObject *populateInstanceAndAliasBindings(
int index, QObject *instance, InitFlags flags);
217 QObject *createInstance(
int index, QObject *parent =
nullptr,
bool isContextObject =
false);
219 QObject *initializeComponent(
220 const QV4::CompiledData::Object *obj, QObject *instance, InitFlags flags);
221 QObject *initializeComposite(
222 int index,
const QV4::CompiledData::Object *obj,
223 const QV4::ResolvedTypeReference *typeRef, QObject *instance, QObject *parent,
225 QObject *initializeNonComposite(
226 int index,
const QV4::CompiledData::Object *obj,
227 const QV4::ResolvedTypeReference *typeRef, QObject *instance, QObject *parent,
230 bool populateInstance(
int index, QObject *instance, QObject *bindingTarget,
232 const QV4::CompiledData::Binding *binding =
nullptr);
235 void populateDeferred(QObject *instance,
int deferredIndex);
236 void populateDeferred(QObject *instance,
int deferredIndex,
237 const QQmlPropertyPrivate *qmlProperty,
238 const QV4::CompiledData::Binding *binding);
242 ApplyImmediate = 0x1,
244 ApplyAll = ApplyImmediate | ApplyDeferred,
246 Q_DECLARE_FLAGS(BindingSetupFlags, BindingMode);
248 void setupBindings(BindingSetupFlags mode = BindingMode::ApplyImmediate);
249 bool setPropertyBinding(
const QQmlPropertyData *property,
const QV4::CompiledData::Binding *binding);
250 void setPropertyValue(
const QQmlPropertyData *property,
const QV4::CompiledData::Binding *binding);
251 void setupFunctions();
253 QString stringAt(
int idx)
const {
return compilationUnit->stringAt(idx); }
254 void recordError(
const QV4::CompiledData::Location &location,
const QString &description);
256 void registerObjectWithContextById(
const QV4::CompiledData::Object *object, QObject *instance)
const;
258 inline QV4::QmlContext *currentQmlContext();
259 QV4::ResolvedTypeReference *resolvedType(
int id)
const
261 return compilationUnit->resolvedType(id);
267 CreatingObjectsPhase2,
274 QV4::ExecutionEngine *v4;
275 QString m_inlineComponentName;
276 QQmlRefPointer<QV4::ExecutableCompilationUnit> compilationUnit;
277 const QV4::CompiledData::Unit *qmlUnit;
278 QQmlGuardedContextData parentContext;
279 QQmlRefPointer<QQmlContextData> context;
280 const QQmlPropertyCacheVector *propertyCaches;
281 QQmlRefPointer<QQmlObjectCreatorSharedState> sharedState;
282 bool topLevelCreator;
283 bool isContextObject;
287 QObject *_scopeObject;
288 QObject *_bindingTarget;
291 int _compiledObjectIndex;
292 const QV4::CompiledData::Object *_compiledObject;
294 QQmlPropertyCache::ConstPtr _propertyCache;
295 QQmlVMEMetaObject *_vmeMetaObject;
296 QQmlListProperty<QObject> _currentList;
297 QV4::QmlContext *_qmlContext;
301 typedef std::function<
bool(QQmlObjectCreatorSharedState *sharedState)> PendingAliasBinding;
302 std::vector<PendingAliasBinding> pendingAliasBindings;
304 template<
typename Functor>
305 void doPopulateDeferred(QObject *instance,
int deferredIndex, Functor f)
307 QQmlData *declarativeData = QQmlData::get(instance);
310 Q_ASSERT(declarativeData && declarativeData->propertyCache);
312 QObject *bindingTarget = instance;
314 QQmlPropertyCache::ConstPtr cache = declarativeData->propertyCache;
315 QQmlVMEMetaObject *vmeMetaObject = QQmlVMEMetaObject::get(instance);
317 QObject *scopeObject = instance;
318 qt_ptr_swap(_scopeObject, scopeObject);
320 QV4::Scope valueScope(v4);
321 QScopedValueRollback<ObjectInCreationGCAnchorList> jsObjectGuard(
322 sharedState->allJavaScriptObjects, ObjectInCreationGCAnchorList(valueScope));
324 Q_ASSERT(topLevelCreator);
325 QV4::QmlContext *qmlContext =
static_cast<QV4::QmlContext *>(valueScope.constructUndefined(1));
327 qt_ptr_swap(_qmlContext, qmlContext);
329 _propertyCache.swap(cache);
330 qt_ptr_swap(_qobject, instance);
332 int objectIndex = deferredIndex;
333 std::swap(_compiledObjectIndex, objectIndex);
335 const QV4::CompiledData::Object *obj = compilationUnit->objectAt(_compiledObjectIndex);
336 qt_ptr_swap(_compiledObject, obj);
337 qt_ptr_swap(_ddata, declarativeData);
338 qt_ptr_swap(_bindingTarget, bindingTarget);
339 qt_ptr_swap(_vmeMetaObject, vmeMetaObject);
343 qt_ptr_swap(_vmeMetaObject, vmeMetaObject);
344 qt_ptr_swap(_bindingTarget, bindingTarget);
345 qt_ptr_swap(_ddata, declarativeData);
346 qt_ptr_swap(_compiledObject, obj);
347 std::swap(_compiledObjectIndex, objectIndex);
348 qt_ptr_swap(_qobject, instance);
349 _propertyCache.swap(cache);
351 qt_ptr_swap(_qmlContext, qmlContext);
352 qt_ptr_swap(_scopeObject, scopeObject);
354 void registerPostHocRequiredProperties(
const QV4::CompiledData::Binding *binding);