145 int objectIndex,
const QQmlPropertyCache::ConstPtr &cache)
147 QList<QV4::CompiledData::BindingPropertyData> &table =
148 cu->baseCompilationUnit()->bindingPropertyDataPerObject;
149 if (objectIndex >= table.size())
152 QV4::CompiledData::BindingPropertyData &bindingData = table[objectIndex];
154 const QV4::CompiledData::Object *obj = cu->objectAt(objectIndex);
155 const QQmlPropertyResolver resolver(cache);
157 const QV4::CompiledData::Binding *binding = obj->bindingTable();
158 for (qsizetype i = 0, end = bindingData.size(); i < end; ++i, ++binding) {
159 if (!bindingData.at(i))
162 Q_ASSERT(i < obj->nBindings);
163 const QString name = BindingPatchContext::targetPropertyName(cu, objectIndex, binding);
167 if (cu->bindingIsSignalHandlerExpression(objectIndex, i)
168 || cu->bindingIsSignalHandlerObject(objectIndex, i)) {
169 bindingData[i] = resolver.signal(
170 *QQmlSignalNames::anyHandlerNameToSignalName(name),
nullptr,
171 QQmlPropertyResolver::IgnoreRevision);
172 }
else if (cu->bindingIsPropertyObserver(objectIndex, i)) {
173 bindingData[i] = resolver.property(
174 *QQmlSignalNames::changedHandlerNameToPropertyName(name),
nullptr,
175 QQmlPropertyResolver::IgnoreRevision);
177 bindingData[i] = resolver.property(
178 name,
nullptr, QQmlPropertyResolver::IgnoreRevision);
221 const QQmlPropertyCache::ConstPtr &oldBaseCache,
222 const QQmlPropertyCache::ConstPtr &newBaseCache)
224 QQmlPropertyCacheVector *caches = cu->propertyCachesPtr();
227 QHash<
const QQmlPropertyCache *, QQmlPropertyCache::ConstPtr> replacements;
228 replacements.insert(oldBaseCache.data(), newBaseCache);
234 for (
int i = 0, end = caches->count(); i < end; ++i) {
235 if (caches->at(i) != oldBaseCache)
237 caches->set(i, newBaseCache);
238 refreshBindingPropertyData(cu, i, newBaseCache);
241 for (
bool changed =
true; changed;) {
243 for (
int i = 0, end = caches->count(); i < end; ++i) {
244 const QQmlPropertyCache::ConstPtr cache = caches->at(i);
248 const auto it = replacements.constFind(cache->parent().data());
249 if (it == replacements.constEnd())
252 const QQmlPropertyCache::ConstPtr rebased = cache->rebased(*it);
253 replacements.insert(cache.data(), rebased);
254 caches->set(i, rebased);
255 refreshBindingPropertyData(cu, i, rebased);
274 const QQmlRefPointer<QV4::ExecutableCompilationUnit> &oldUnit,
275 const QQmlRefPointer<QV4::ExecutableCompilationUnit> &newUnit)
277 std::vector<CompositeLevel> levels;
279 auto currentUnit = instanceLevel.newCu;
280 const QV4::CompiledData::Object *obj = currentUnit->objectAt(instanceLevel.objectIndex);
281 const QV4::ResolvedTypeReference *typeRef =
282 currentUnit->resolvedType(obj->inheritedTypeNameIndex);
284 while (typeRef && typeRef->type().isComposite()) {
285 QQmlRefPointer<QV4::ExecutableCompilationUnit> cu = typeRef->isSelfReference()
287 : currentUnit->engine->executableCompilationUnit(typeRef->compilationUnit());
291 const auto oldCu = cu;
297 if (typeRef->type().isInlineComponent()) {
298 icName = typeRef->type().elementName();
299 rootIndex = cu->inlineComponentId(icName);
304 levels.push_back({ oldCu, cu, rootIndex, icName,
nullptr });
306 if (rootIndex < 0 || rootIndex >= cu->objectCount())
310 const QV4::CompiledData::Object *rootObj = cu->objectAt(rootIndex);
311 typeRef = cu->resolvedType(rootObj->inheritedTypeNameIndex);
357 const QQmlRefPointer<QV4::ExecutableCompilationUnit> &oldUnit,
358 const QQmlRefPointer<QV4::ExecutableCompilationUnit> &newUnit,
359 ReplacedContexts *replacedContexts)
362 if (cuIndex >= newUnit->objectCount())
365 QQmlData *ddata = QQmlData::get(object);
368 QQmlRefPointer<QQmlContextData> outerContext =
369 QQmlRefPointer<QQmlContextData>(ddata->outerContext);
372 if (!ddata->context || !outerContext || !outerContext->isValid() || ddata->isQueuedForDeletion)
375 CompositeLevel instanceLevel{ ddata->compilationUnit,
376 ddata->compilationUnit == oldUnit ? newUnit
377 : ddata->compilationUnit,
378 ddata->cuObjectIndex, QString(), outerContext };
382 if (instanceLevel.objectIndex >= instanceLevel.newCu->objectCount())
385 std::vector<CompositeLevel> levels = collectCompositeLevels(instanceLevel, oldUnit, newUnit);
389 std::vector<CompositeLevel> internalUnits;
390 internalUnits.push_back(instanceLevel);
391 for (
const auto &level : levels)
392 internalUnits.push_back(level);
394 BindingPatchContext patchCtx(object, ddata->compilationUnit, ddata->cuObjectIndex);
395 QDuplicateTracker<QObject *> seenChildren;
396 patchCtx.stashExternalState(internalUnits, &seenChildren);
401 std::vector<QQmlRefPointer<QV4::ExecutableCompilationUnit>> unitsToUnparent;
402 unitsToUnparent.push_back(oldUnit);
403 for (
const auto &level : levels)
404 unitsToUnparent.push_back(level.oldCu);
405 patchCtx.reset(unitsToUnparent, internalUnits);
407 QV4::ExecutionEngine *v4 = newUnit->engine;
409 QQmlEnginePrivate *enginePrivate = QQmlEnginePrivate::get(v4);
410 Q_ASSERT(enginePrivate);
412 const QVarLengthArray<QQmlRefPointer<QQmlContextData>, 4> oldLevelContexts =
413 levelContexts(object, outerContext);
415 if (outerContext->contextObject() == object) {
416 const QQmlRefPointer<QQmlContextData> oldOuterContext = outerContext;
417 oldOuterContext->setContextObject(
nullptr);
418 outerContext = enginePrivate->createComponentRootContext(
419 instanceLevel.newCu, currentContext(oldOuterContext->parent(), *replacedContexts),
420 instanceLevel.objectIndex);
421 outerContext->setContextObject(object);
422 instanceLevel.context = outerContext;
423 replacedContexts->insert(oldOuterContext.data(), { oldOuterContext, outerContext });
426 for (QQmlRefPointer<QQmlContextData> ctx(ddata->context); ctx; ctx = ctx->linkedContext()) {
427 if (ctx->contextObject() == object)
428 ctx->setContextObject(
nullptr);
436 if (
const QV4::CompiledData::Object *declaration =
437 instanceLevel.newCu->objectAt(instanceLevel.objectIndex)) {
438 ddata->lineNumber = declaration->location.line();
439 ddata->columnNumber = declaration->location.column();
442 QObjectPrivate *objectPrivate = QObjectPrivate::get(object);
443 delete std::exchange(objectPrivate->metaObject,
nullptr);
445 QQmlRefPointer<QQmlContextData> levelContext = outerContext;
446 qsizetype replacedLevels = 0;
447 for (qsizetype i = 0, end = levels.size(); i < end; ++i) {
448 CompositeLevel &level = levels[i];
449 levelContext = level.context = enginePrivate->createComponentRootContext(
450 level.newCu, levelContext, level.objectIndex);
451 levelContext->setContextObject(object);
455 if (i >= oldLevelContexts.size() || i != replacedLevels)
457 const QQmlRefPointer<QQmlContextData> &oldLevelContext = oldLevelContexts[i];
458 const QQmlRefPointer<QV4::ExecutableCompilationUnit> oldLevelCu =
459 oldLevelContext->typeCompilationUnit();
460 if ((oldLevelCu == oldUnit ? newUnit : oldLevelCu) != level.newCu)
462 replacedContexts->insert(oldLevelContext.data(), { oldLevelContext, levelContext });
466 if (outerContext->contextObject() == object) {
467 ddata->ownContext = outerContext;
468 ddata->context = outerContext.data();
470 ddata->context->setLinkedContext(levels.front().context);
471 }
else if (!levels.empty()) {
472 ddata->ownContext = levels.back().context;
473 ddata->context = ddata->ownContext.data();
474 if (levels.size() > 1)
475 ddata->context->setLinkedContext(levels.front().context);
478 ddata->context = outerContext.data();
484 QQmlPropertyCache::ConstPtr parentCache;
485 for (
auto it = levels.crbegin(), end = levels.crend(); it != end; ++it) {
486 it->context->addOwnedObject(ddata);
487 QQmlPropertyCache::ConstPtr cache = relinkCache(it->newCu, it->objectIndex, parentCache);
488 if (it->newCu->propertyCachesPtr()->needsVMEMetaObject(it->objectIndex))
489 new QQmlVMEMetaObject(v4, object, cache, it->newCu, it->objectIndex);
493 outerContext->addOwnedObject(ddata);
494 if (QQmlPropertyCacheVector *caches = instanceLevel.newCu->propertyCachesPtr();
495 caches->count() > instanceLevel.objectIndex) {
496 QQmlPropertyCache::ConstPtr cache =
497 relinkCache(instanceLevel.newCu, instanceLevel.objectIndex, parentCache);
498 if (caches->needsVMEMetaObject(instanceLevel.objectIndex))
499 new QQmlVMEMetaObject(v4, object, cache, instanceLevel.newCu, instanceLevel.objectIndex);
506 for (
auto it = levels.crbegin(), end = levels.crend(); it != end && !ddata->isQueuedForDeletion;
508 QQmlObjectCreator creator(it->context, it->newCu, outerContext, it->icName,
nullptr);
509 creator.repopulateBindings(it->objectIndex, object, it->context,
510 QQmlObjectCreator::InitFlag::IsContextObject
511 | QQmlObjectCreator::InitFlag::IsDocumentRoot);
513 QQmlInstantiationInterrupt interrupt;
514 creator.finalize(interrupt);
519 if (!ddata->isQueuedForDeletion) {
521 QQmlObjectCreator creator(instanceLevel.context, instanceLevel.newCu, outerContext, QString(),
523 creator.repopulateBindings(instanceLevel.objectIndex, object, outerContext,
524 QQmlObjectCreator::InitFlag::None);
525 QQmlInstantiationInterrupt interrupt;
526 creator.finalize(interrupt);
530 patchCtx.refreshObjects();
531 patchCtx.restoreExternalState();
558 const QQmlRefPointer<QV4::ExecutableCompilationUnit> &oldUnit,
559 const QQmlRefPointer<QV4::ExecutableCompilationUnit> &newUnit)
561 using ChangeType = QV4::CompiledData::ChangeType;
562 switch (change.type) {
564 case ChangeType::AliasLocationChanged:
565 case ChangeType::BindingLocationChanged:
566 case ChangeType::EnumLocationChanged:
567 case ChangeType::FunctionLocationChanged:
568 case ChangeType::ImportLocationChanged:
569 case ChangeType::InlineComponentLocationChanged:
570 case ChangeType::ObjectLocationChanged:
571 case ChangeType::PropertyLocationChanged:
572 case ChangeType::RequiredPropertyExtraDataLocationChanged:
573 case ChangeType::SignalLocationChanged:
578 case ChangeType::BindingIndexChanged:
579 case ChangeType::EnumIndexChanged:
580 case ChangeType::InlineComponentIndexChanged:
581 case ChangeType::RequiredPropertyExtraDataIndexChanged:
591 case ChangeType::PropertyAdded:
592 case ChangeType::PropertyIndexChanged:
593 case ChangeType::PropertyRemoved:
597 case ChangeType::UnitMetadataChanged:
598 case ChangeType::ConstantAdded:
599 case ChangeType::ConstantChanged:
600 case ChangeType::ConstantRemoved:
601 case ChangeType::StringDataAdded:
602 case ChangeType::StringDataChanged:
603 case ChangeType::StringDataRemoved:
604 case ChangeType::LookupAdded:
605 case ChangeType::LookupChanged:
606 case ChangeType::LookupRemoved:
607 case ChangeType::RegExpAdded:
608 case ChangeType::RegExpChanged:
609 case ChangeType::RegExpRemoved:
610 case ChangeType::ClassAdded:
611 case ChangeType::ClassChanged:
612 case ChangeType::ClassRemoved:
613 case ChangeType::BlockAdded:
614 case ChangeType::BlockChanged:
615 case ChangeType::BlockRemoved:
616 case ChangeType::TemplateObjectAdded:
617 case ChangeType::TemplateObjectChanged:
618 case ChangeType::TemplateObjectRemoved:
619 case ChangeType::JSClassAdded:
620 case ChangeType::JSClassChanged:
621 case ChangeType::JSClassRemoved:
622 case ChangeType::TranslationDataAdded:
623 case ChangeType::TranslationDataChanged:
624 case ChangeType::TranslationDataRemoved:
626 case ChangeType::FunctionAdded:
627 case ChangeType::FunctionChanged:
628 case ChangeType::FunctionIndexChanged:
629 case ChangeType::FunctionRemoved:
635 case ChangeType::BindingChanged: {
636 Q_ASSERT(change.objectIndex >= 0);
637 Q_ASSERT(change.objectIndex < oldUnit->objectCount());
638 Q_ASSERT(change.objectIndex < newUnit->objectCount());
640 const QV4::CompiledData::Object *oldObj = oldUnit->objectAt(change.objectIndex);
641 Q_ASSERT(change.oldIndex < oldObj->nBindings);
642 const QV4::CompiledData::Binding *oldBinding = oldObj->bindingTable() + change.oldIndex;
644 const QV4::CompiledData::Object *newObj = newUnit->objectAt(change.objectIndex);
645 Q_ASSERT(change.newIndex < newObj->nBindings);
646 const QV4::CompiledData::Binding *newBinding = newObj->bindingTable() + change.newIndex;
648 const BindingKind oldKind = bindingKind(oldBinding);
649 const BindingKind newKind = bindingKind(newBinding);
657 if (oldKind != newKind)
665 return BindingPatchContext::targetPropertyName(oldUnit, change.objectIndex, oldBinding)
666 == BindingPatchContext::targetPropertyName(newUnit, change.objectIndex, newBinding);
668 case ChangeType::BindingAdded:
669 case ChangeType::BindingRemoved: {
674 const bool added = change.type == ChangeType::BindingAdded;
675 const QQmlRefPointer<QV4::ExecutableCompilationUnit> &unit = added ? newUnit : oldUnit;
676 const quint32 bindingIndex = added ? change.newIndex : change.oldIndex;
678 Q_ASSERT(change.objectIndex >= 0 && change.objectIndex < unit->objectCount());
679 const QV4::CompiledData::Object *obj = unit->objectAt(change.objectIndex);
680 Q_ASSERT(bindingIndex < obj->nBindings);
686 return unit->resolvedType(obj->inheritedTypeNameIndex) !=
nullptr;
751 const QQmlRefPointer<QV4::ExecutableCompilationUnit> &oldUnit,
752 const QQmlRefPointer<QV4::ExecutableCompilationUnit> &newUnit)
754 for (QObject *object : objects) {
755 QQmlData *ddata = QQmlData::get(object);
759 if (QQmlComponent *component = qobject_cast<QQmlComponent *>(object)) {
760 QQmlComponentPrivate *cp = QQmlComponentPrivate::get(component);
761 if (cp->compilationUnit() == oldUnit)
762 cp->setCompilationUnit(newUnit);
768 if (ddata->compilationUnit == oldUnit && ddata->cuObjectIndex < newUnit->objectCount())
769 ddata->compilationUnit = newUnit;
771 if (!ddata->hasVMEMetaObject)
775 auto *mainVme =
static_cast<QQmlVMEMetaObject *>(QObjectPrivate::get(object)->metaObject);
776 for (QQmlVMEMetaObject *vmeMeta = mainVme; vmeMeta;
777 vmeMeta = vmeMeta->parentVMEMetaObject()) {
778 if (vmeMeta->compilationUnit() != oldUnit)
780 if (vmeMeta->qmlObjectId() < newUnit->objectCount()) {
781 vmeMeta->setCompilationUnit(newUnit);
785 const QQmlPropertyCache::ConstPtr newCache =
786 newUnit->propertyCachesPtr()->at(vmeMeta->qmlObjectId());
788 vmeMeta->setPropertyCache(newCache);
789 if (vmeMeta == mainVme)
790 ddata->propertyCache = newCache;
795 vmeMeta->setCompilationUnit(
nullptr);
896 const QQmlRefPointer<QV4::ExecutableCompilationUnit> &newUnit)
898 QV4::ExecutionEngine *v4 = newUnit->engine;
899 QV4::Scope scope(v4);
900 QV4::ScopedValue function(scope);
902 for (QObject *object : objects) {
903 QQmlData *ddata = QQmlData::get(object);
904 if (!ddata || !ddata->hasVMEMetaObject)
907 auto *mainVme =
static_cast<QQmlVMEMetaObject *>(QObjectPrivate::get(object)->metaObject);
908 for (QQmlVMEMetaObject *vme = mainVme; vme; vme = vme->parentVMEMetaObject()) {
909 const auto cu = vme->compilationUnit();
913 const QQmlRefPointer<QQmlContextData> context = vme->contextData();
917 const int objectIndex = vme->qmlObjectId();
918 if (objectIndex < 0 || objectIndex >= cu->objectCount())
921 const QV4::CompiledData::Object *obj = cu->objectAt(objectIndex);
922 const QQmlPropertyCache::ConstPtr cache = cu->propertyCachesPtr()->at(objectIndex);
926 QV4::Scoped<QV4::QmlContext> qmlContext(
927 scope, QV4::QmlContext::create(v4->rootContext(), context, object));
929 const quint32_le *functionIdx = obj->functionOffsetTable();
930 for (quint32 i = 0; i < obj->nFunctions; ++i, ++functionIdx) {
931 QV4::Function *runtimeFunction = cu->runtimeFunctions[*functionIdx];
932 const QString name = runtimeFunction->name()->toQString();
934 const QQmlPropertyData *property = cache->property(name, object, context);
935 if (!property || !property->isVMEFunction())
939 function = runtimeFunction->isGenerator()
940 ? QV4::GeneratorFunction::create(qmlContext, runtimeFunction)
941 : QV4::FunctionObject::createScriptFunction(qmlContext, runtimeFunction);
942 mainVme->setVmeMethod(property->coreIndex(), function);
959 const QV4::CompiledData::CompilationUnitDiff &diff,
960 const QQmlRefPointer<QV4::ExecutableCompilationUnit> &oldUnit,
961 const QQmlRefPointer<QV4::ExecutableCompilationUnit> &newUnit)
963 using ChangeType = QV4::CompiledData::ChangeType;
965 QHash<
int, PropertyReshape> reshapes;
967 auto it = reshapes.find(objectIndex);
968 if (it != reshapes.end())
971 Q_ASSERT(objectIndex >= 0 && objectIndex < oldUnit->objectCount());
972 const int oldCount = oldUnit->objectAt(objectIndex)->nProperties;
973 const int newCount = objectIndex < newUnit->objectCount()
974 ? newUnit->objectAt(objectIndex)->nProperties
978 reshape.oldToNew.resize(oldCount);
979 for (
int i = 0; i < oldCount; ++i)
980 reshape.oldToNew[i] = i;
981 return *reshapes.insert(objectIndex, reshape);
984 for (
const QV4::CompiledData::Change &change : diff.changes) {
985 switch (change.type) {
986 case ChangeType::PropertyIndexChanged: {
987 PropertyReshape &reshape = ensure(change.objectIndex);
988 Q_ASSERT(change.oldIndex < quint32(reshape.oldToNew.size()));
989 Q_ASSERT(change.newIndex < quint32(reshape.newPropertyCount));
990 reshape.oldToNew[change.oldIndex] =
int(change.newIndex);
993 case ChangeType::PropertyRemoved: {
995 PropertyReshape &reshape = ensure(change.objectIndex);
996 Q_ASSERT(change.oldIndex < quint32(reshape.oldToNew.size()));
997 reshape.oldToNew[change.oldIndex] = -1;
1000 case ChangeType::PropertyAdded:
1003 ensure(change.objectIndex);
1010 if (reshapes.isEmpty())
1013 for (QObject *object : objects) {
1014 QQmlData *ddata = QQmlData::get(object);
1015 if (!ddata || !ddata->hasVMEMetaObject)
1018 for (QQmlVMEMetaObject *vme =
1019 static_cast<QQmlVMEMetaObject *>(QObjectPrivate::get(object)->metaObject);
1020 vme; vme = vme->parentVMEMetaObject()) {
1021 if (vme->compilationUnit() != oldUnit)
1023 const auto it = reshapes.constFind(vme->qmlObjectId());
1024 if (it != reshapes.constEnd())
1025 vme->remapProperties(it->newPropertyCount, it->oldToNew);
1192 const QV4::CompiledData::CompilationUnitDiff &diff,
const CuRef &oldUnit,
1193 const CuRef &newUnit)
1195 using ChangeType = QV4::CompiledData::ChangeType;
1197 QHash<
int, QSet<QString>> affected;
1198 for (
const QV4::CompiledData::Change &change : diff.changes) {
1200 switch (change.type) {
1201 case ChangeType::BindingAdded:
1202 name = BindingPatchContext::targetPropertyName(
1203 newUnit, change.objectIndex,
1204 bindingAt(newUnit, change.objectIndex, change.newIndex));
1206 case ChangeType::BindingRemoved:
1207 name = BindingPatchContext::targetPropertyName(
1208 oldUnit, change.objectIndex,
1209 bindingAt(oldUnit, change.objectIndex, change.oldIndex));
1211 case ChangeType::BindingChanged:
1214 if (isScriptBinding(bindingAt(newUnit, change.objectIndex, change.newIndex))
1215 != isScriptBinding(bindingAt(oldUnit, change.objectIndex, change.oldIndex))) {
1216 name = BindingPatchContext::targetPropertyName(
1217 newUnit, change.objectIndex,
1218 bindingAt(newUnit, change.objectIndex, change.newIndex));
1224 if (!name.isEmpty())
1225 affected[change.objectIndex].insert(name);
1325 const QQmlRefPointer<QV4::ExecutableCompilationUnit> &oldUnit,
1326 const QQmlRefPointer<QV4::ExecutableCompilationUnit> &newUnit)
1329 if (!newUnit->runtimeStrings)
1330 newUnit->populate();
1338 const QV4::CompiledData::CompilationUnitDiff diff =
1339 QV4::CompiledData::diffCompilationUnits(oldUnit->unitData(), newUnit->unitData());
1340 if (diff.success && isTrivialDiff(diff, oldUnit, newUnit)) {
1341 patchConstantBindings(objects, diff, oldUnit, newUnit);
1345 reshapeProperties(objects, diff, oldUnit, newUnit);
1350 const bool derivedAffected = propertyCountChangeAffectsDerived(diff, objects, oldUnit);
1351 if (derivedAffected) {
1352 redirectResolvedTypeReferences(newUnit->engine, oldUnit->baseCompilationUnit(),
1353 newUnit->baseCompilationUnit());
1355 remapObjectsToNewUnit(objects, oldUnit, newUnit);
1356 if (derivedAffected)
1357 relinkDerivedInstanceCaches(objects);
1358 refreshVmeMethods(objects, newUnit);
1361 applyBindingChanges(objects, diff, oldUnit, newUnit);
1385 std::vector<RebuildTarget> rebuild;
1386 QSet<QObject *> rebuildSet;
1387 bool redirectedTypes =
false;
1389 const auto addRebuild = [&](QObject *object,
int index,
1390 const QQmlRefPointer<QV4::ExecutableCompilationUnit> &oldCu,
1391 const QQmlRefPointer<QV4::ExecutableCompilationUnit> &newCu) {
1392 if (rebuildSet.contains(object))
1394 rebuildSet.insert(object);
1395 rebuild.push_back({ object, index, oldCu, newCu });
1398 for (QObject *object : objects) {
1399 const QVarLengthArray<
int, 4> indices = objectIndices(object, oldUnit);
1400 for (
int index : indices) {
1405 if (index >= oldUnit->objectCount() || !isComponentRoot(oldUnit, index))
1414 if (!canRebuildComponentRootInPlace(oldUnit, newUnit, index)) {
1415 QObject *outer = outerRebuildTarget(object, oldUnit, newUnit);
1417 return PatchResult::Failed;
1422 if (!redirectedTypes) {
1423 redirectResolvedTypeReferences(newUnit->engine, oldUnit->baseCompilationUnit(),
1424 newUnit->baseCompilationUnit());
1425 redirectedTypes =
true;
1431 const QQmlRefPointer<QV4::ExecutableCompilationUnit> outerOld =
1432 QQmlData::get(outer)->compilationUnit;
1433 const QQmlRefPointer<QV4::ExecutableCompilationUnit> outerNew =
1434 outerOld->baseCompilationUnit() == oldUnit->baseCompilationUnit()
1437 addRebuild(outer, QQmlData::get(outer)->cuObjectIndex, outerOld, outerNew);
1441 addRebuild(object, indices.first(), oldUnit, newUnit);
1450 std::sort(rebuild.begin(), rebuild.end(),
1451 [](
const RebuildTarget &a,
const RebuildTarget &b) {
return a.index < b.index; });
1456 QSet<QObject *> skip;
1457 for (
const RebuildTarget &target : rebuild) {
1458 const QObjectList &children = target.object->children();
1459 for (QObject *child : children)
1463 ReplacedContexts replacedContexts;
1464 for (
const RebuildTarget &target : rebuild) {
1465 if (skip.contains(target.object))
1468 rebuildObject(target.object, target.index, target.oldCu, target.newCu, &replacedContexts);
1474 for (QObject *object : objects) {
1475 const QQmlData *ddata = QQmlData::get(object);
1476 if (ddata->compilationUnit != oldUnit || ddata->isQueuedForDeletion)
1478 BindingPatchContext::clearBindingsRecursive(object);
1479 BindingPatchContext::retireObject(object);
1493 const QQmlRefPointer<QV4::ExecutableCompilationUnit> &newUnit)
1495 const auto collect = [](
const QQmlRefPointer<QV4::ExecutableCompilationUnit> &unit,
1497 QHash<QString,
int> keyToGlobalIndex;
1498 QHash<QString,
int> seen;
1499 const QV4::CompiledData::Unit *data = unit->unitData();
1500 const QV4::CompiledData::Object *obj = data->qmlUnit()->objectAt(objectIndex);
1501 const auto add = [&](quint32 globalIndex) {
1502 const QString name = data->stringAtInternal(data->functionAt(globalIndex)->nameIndex);
1503 keyToGlobalIndex.insert(name + QChar(QChar::Null) + QString::number(seen[name]++),
1506 const quint32_le *methods = obj->functionOffsetTable();
1507 for (quint32 m = 0; m < obj->nFunctions; ++m)
1509 const QV4::CompiledData::Binding *bindings = obj->bindingTable();
1510 for (quint32 b = 0; b < obj->nBindings; ++b) {
1511 if (bindings[b].type() == QV4::CompiledData::Binding::Type_Script)
1512 add(bindings[b].value.compiledScriptIndex);
1514 return keyToGlobalIndex;
1517 QHash<QV4::Function *, QV4::Function *> map;
1518 const int count =
std::min(oldUnit->objectCount(), newUnit->objectCount());
1519 for (
int o = 0; o < count; ++o) {
1520 const QHash<QString,
int> oldKeys = collect(oldUnit, o);
1521 const QHash<QString,
int> newKeys = collect(newUnit, o);
1522 for (
auto it = oldKeys.constBegin(), end = oldKeys.constEnd(); it != end; ++it) {
1523 const auto newIt = newKeys.constFind(it.key());
1524 if (newIt == newKeys.constEnd())
1526 QV4::Function *oldFunction = oldUnit->runtimeFunctions.value(it.value());
1527 QV4::Function *newFunction = newUnit->runtimeFunctions.value(newIt.value());
1528 if (oldFunction && newFunction)
1529 map.insert(oldFunction, newFunction);