diff options
author | Lars Knoll <[email protected]> | 2013-09-18 11:00:38 +0200 |
---|---|---|
committer | The Qt Project <[email protected]> | 2013-09-22 01:06:20 +0200 |
commit | 50624234f2c0b6d3b0985edb8ff0b6aad5cad761 (patch) | |
tree | 2852c8917788d870100278d1cdc0129b94c5b599 /src | |
parent | 8b3623ee7b707e1b26ad48bdbf7816b95d9e0e24 (diff) |
Add a Safe<T> class and start using it
The class denotes objects that are stored safely
in areas controlled by the GC. These we can convert
fast to a StringRef etc.
Change-Id: I6b154eccaefddc42d4fafca55b7ee9e77179830c
Reviewed-by: Simon Hausmann <[email protected]>
Reviewed-by: Gunnar Sletta <[email protected]>
Diffstat (limited to 'src')
-rw-r--r-- | src/imports/dialogs-private/qquickfontlistmodel.cpp | 8 | ||||
-rw-r--r-- | src/imports/dialogs-private/qquickwritingsystemlistmodel.cpp | 8 | ||||
-rw-r--r-- | src/imports/xmllistmodel/qqmlxmllistmodel.cpp | 3 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4engine_p.h | 56 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4jsonobject.cpp | 4 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4object.cpp | 20 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4object_p.h | 2 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4objectproto.cpp | 2 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4regexpobject.cpp | 5 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4runtime.cpp | 20 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4scopedvalue_p.h | 37 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4value_def_p.h | 16 | ||||
-rw-r--r-- | src/qml/qml/v8/qv8engine.cpp | 4 | ||||
-rw-r--r-- | src/qml/types/qqmldelegatemodel.cpp | 27 | ||||
-rw-r--r-- | src/qml/util/qqmladaptormodel.cpp | 4 |
15 files changed, 145 insertions, 71 deletions
diff --git a/src/imports/dialogs-private/qquickfontlistmodel.cpp b/src/imports/dialogs-private/qquickfontlistmodel.cpp index 234a5735ec..233001b723 100644 --- a/src/imports/dialogs-private/qquickfontlistmodel.cpp +++ b/src/imports/dialogs-private/qquickfontlistmodel.cpp @@ -216,13 +216,15 @@ QQmlV4Handle QQuickFontListModel::get(int idx) const QQmlEngine *engine = qmlContext(this)->engine(); QV8Engine *v8engine = QQmlEnginePrivate::getV8Engine(engine); ExecutionEngine *v4engine = QV8Engine::getV4(v8engine); - Object *o = v4engine->newObject(); + Scope scope(v4engine); + ScopedObject o(scope, v4engine->newObject()); + ScopedString s(scope); for (int ii = 0; ii < d->roleNames.keys().count(); ++ii) { - Property *p = o->insertMember(v4engine->newIdentifier(d->roleNames[Qt::UserRole + ii + 1]), PropertyAttributes()); + Property *p = o->insertMember((s = v4engine->newIdentifier(d->roleNames[Qt::UserRole + ii + 1])), PropertyAttributes()); p->value = Value::fromReturnedValue(v8engine->fromVariant(data(index(idx, 0), Qt::UserRole + ii + 1))); } - return QQmlV4Handle(Value::fromObject(o)); + return QQmlV4Handle(o.asValue()); } QQmlV4Handle QQuickFontListModel::pointSizes() diff --git a/src/imports/dialogs-private/qquickwritingsystemlistmodel.cpp b/src/imports/dialogs-private/qquickwritingsystemlistmodel.cpp index 08caa662c2..ffe82fce12 100644 --- a/src/imports/dialogs-private/qquickwritingsystemlistmodel.cpp +++ b/src/imports/dialogs-private/qquickwritingsystemlistmodel.cpp @@ -154,13 +154,15 @@ QQmlV4Handle QQuickWritingSystemListModel::get(int idx) const QQmlEngine *engine = qmlContext(this)->engine(); QV8Engine *v8engine = QQmlEnginePrivate::getV8Engine(engine); ExecutionEngine *v4engine = QV8Engine::getV4(v8engine); - Object *o = v4engine->newObject(); + Scope scope(v4engine); + ScopedObject o(scope, v4engine->newObject()); + ScopedString s(scope); for (int ii = 0; ii < d->roleNames.keys().count(); ++ii) { - Property *p = o->insertMember(v4engine->newIdentifier(d->roleNames[Qt::UserRole + ii + 1]), PropertyAttributes()); + Property *p = o->insertMember((s = v4engine->newIdentifier(d->roleNames[Qt::UserRole + ii + 1])), PropertyAttributes()); p->value = Value::fromReturnedValue(v8engine->fromVariant(data(index(idx, 0), Qt::UserRole + ii + 1))); } - return QQmlV4Handle(Value::fromObject(o)); + return QQmlV4Handle(o.asValue()); } void QQuickWritingSystemListModel::classBegin() diff --git a/src/imports/xmllistmodel/qqmlxmllistmodel.cpp b/src/imports/xmllistmodel/qqmlxmllistmodel.cpp index f87273be40..2991bd9755 100644 --- a/src/imports/xmllistmodel/qqmlxmllistmodel.cpp +++ b/src/imports/xmllistmodel/qqmlxmllistmodel.cpp @@ -926,7 +926,8 @@ QQmlV4Handle QQuickXmlListModel::get(int index) const Scope scope(v4engine); Scoped<Object> o(scope, v4engine->newObject()); for (int ii = 0; ii < d->roleObjects.count(); ++ii) { - Property *p = o->insertMember(v4engine->newIdentifier(d->roleObjects[ii]->name()), PropertyAttributes()); + ScopedString name(scope, v4engine->newIdentifier(d->roleObjects[ii]->name())); + Property *p = o->insertMember(name, PropertyAttributes()); p->value = Value::fromReturnedValue(v8engine->fromVariant(d->data.value(ii).value(index))); } diff --git a/src/qml/jsruntime/qv4engine_p.h b/src/qml/jsruntime/qv4engine_p.h index 1cbf32e622..0bc5f81d23 100644 --- a/src/qml/jsruntime/qv4engine_p.h +++ b/src/qml/jsruntime/qv4engine_p.h @@ -198,34 +198,34 @@ struct Q_QML_EXPORT ExecutionEngine QVector<Property> argumentsAccessors; - String *id_undefined; - String *id_null; - String *id_true; - String *id_false; - String *id_boolean; - String *id_number; - String *id_string; - String *id_object; - String *id_function; - String *id_length; - String *id_prototype; - String *id_constructor; - String *id_arguments; - String *id_caller; - String *id_callee; - String *id_this; - String *id___proto__; - String *id_enumerable; - String *id_configurable; - String *id_writable; - String *id_value; - String *id_get; - String *id_set; - String *id_eval; - String *id_uintMax; - String *id_name; - String *id_index; - String *id_input; + SafeString id_undefined; + SafeString id_null; + SafeString id_true; + SafeString id_false; + SafeString id_boolean; + SafeString id_number; + SafeString id_string; + SafeString id_object; + SafeString id_function; + SafeString id_length; + SafeString id_prototype; + SafeString id_constructor; + SafeString id_arguments; + SafeString id_caller; + SafeString id_callee; + SafeString id_this; + SafeString id___proto__; + SafeString id_enumerable; + SafeString id_configurable; + SafeString id_writable; + SafeString id_value; + SafeString id_get; + SafeString id_set; + SafeString id_eval; + SafeString id_uintMax; + SafeString id_name; + SafeString id_index; + SafeString id_input; QSet<CompiledData::CompilationUnit*> compilationUnits; QMap<quintptr, QV4::Function*> allFunctions; diff --git a/src/qml/jsruntime/qv4jsonobject.cpp b/src/qml/jsruntime/qv4jsonobject.cpp index aa6b261928..df6de78710 100644 --- a/src/qml/jsruntime/qv4jsonobject.cpp +++ b/src/qml/jsruntime/qv4jsonobject.cpp @@ -281,7 +281,9 @@ bool JsonParser::parseMember(Object *o) if (!parseValue(&val)) return false; - Property *p = o->insertMember(context->engine->newIdentifier(key), Attr_Data); + Scope scope(o->engine()); + ScopedString s(scope, context->engine->newIdentifier(key)); + Property *p = o->insertMember(s, Attr_Data); p->value = val; END; diff --git a/src/qml/jsruntime/qv4object.cpp b/src/qml/jsruntime/qv4object.cpp index e157faaf67..b232718125 100644 --- a/src/qml/jsruntime/qv4object.cpp +++ b/src/qml/jsruntime/qv4object.cpp @@ -217,7 +217,7 @@ void Object::inplaceBinOp(ExecutionContext *ctx, BinOpContext op, const ValueRef void Object::defineDefaultProperty(const StringRef name, Value value) { - Property *pd = insertMember(name.getPointer(), Attr_Data|Attr_NotEnumerable); + Property *pd = insertMember(name, Attr_Data|Attr_NotEnumerable); pd->value = value; } @@ -266,7 +266,7 @@ void Object::defineAccessorProperty(ExecutionEngine *engine, const QString &name void Object::defineAccessorProperty(const StringRef name, ReturnedValue (*getter)(SimpleCallContext *), ReturnedValue (*setter)(SimpleCallContext *)) { ExecutionEngine *v4 = engine(); - Property *p = insertMember(name.getPointer(), QV4::Attr_Accessor|QV4::Attr_NotConfigurable|QV4::Attr_NotEnumerable); + Property *p = insertMember(name, QV4::Attr_Accessor|QV4::Attr_NotConfigurable|QV4::Attr_NotEnumerable); if (getter) p->setGetter(v4->newBuiltinFunction(v4->rootContext, name, getter)->getPointer()); @@ -281,7 +281,9 @@ void Object::defineReadonlyProperty(ExecutionEngine *engine, const QString &name void Object::defineReadonlyProperty(String *name, Value value) { - Property *pd = insertMember(name, Attr_ReadOnly); + Scope scope(engine()); + ScopedString s(scope, name); + Property *pd = insertMember(s, Attr_ReadOnly); pd->value = value; } @@ -317,10 +319,10 @@ void Object::ensureMemberIndex(uint idx) } } -Property *Object::insertMember(String *s, PropertyAttributes attributes) +Property *Object::insertMember(const StringRef s, PropertyAttributes attributes) { uint idx; - internalClass = internalClass->addMember(s, attributes, &idx); + internalClass = internalClass->addMember(s.getPointer(), attributes, &idx); if (attributes.isAccessor()) hasAccessorProperty = 1; @@ -785,7 +787,9 @@ void Object::internalPut(String *name, const Value &value) } { - Property *p = insertMember(name, Attr_Data); + Scope scope(engine()); + ScopedString s(scope, name); + Property *p = insertMember(s, Attr_Data); p->value = value; return; } @@ -969,7 +973,9 @@ bool Object::__defineOwnProperty__(ExecutionContext *ctx, String *name, const Pr if (!extensible) goto reject; // clause 4 - Property *pd = insertMember(name, attrs); + Scope scope(engine()); + ScopedString s(scope, name); + Property *pd = insertMember(s, attrs); *pd = p; pd->fullyPopulated(&attrs); return true; diff --git a/src/qml/jsruntime/qv4object_p.h b/src/qml/jsruntime/qv4object_p.h index c0676667a4..b21bd7bec6 100644 --- a/src/qml/jsruntime/qv4object_p.h +++ b/src/qml/jsruntime/qv4object_p.h @@ -174,7 +174,7 @@ struct Q_QML_EXPORT Object: Managed { void defineReadonlyProperty(ExecutionEngine *engine, const QString &name, Value value); void defineReadonlyProperty(String *name, Value value); - Property *insertMember(String *s, PropertyAttributes attributes); + Property *insertMember(const StringRef s, PropertyAttributes attributes); inline ExecutionEngine *engine() const { return internalClass->engine; } diff --git a/src/qml/jsruntime/qv4objectproto.cpp b/src/qml/jsruntime/qv4objectproto.cpp index 3b07527355..d0a94e8de7 100644 --- a/src/qml/jsruntime/qv4objectproto.cpp +++ b/src/qml/jsruntime/qv4objectproto.cpp @@ -133,7 +133,7 @@ void ObjectPrototype::init(ExecutionContext *ctx, const Value &ctor) defineDefaultProperty(ctx, QStringLiteral("__defineSetter__"), method_defineSetter, 2); Scoped<String> id_proto(scope, v4->id___proto__); - Property *p = insertMember(v4->id___proto__, Attr_Accessor|Attr_NotEnumerable); + Property *p = insertMember(StringRef(v4->id___proto__), Attr_Accessor|Attr_NotEnumerable); p->setGetter(v4->newBuiltinFunction(v4->rootContext, id_proto, method_get_proto)->getPointer()); p->setSetter(v4->newBuiltinFunction(v4->rootContext, id_proto, method_set_proto)->getPointer()); } diff --git a/src/qml/jsruntime/qv4regexpobject.cpp b/src/qml/jsruntime/qv4regexpobject.cpp index 60a5026772..aa3f1c3fb5 100644 --- a/src/qml/jsruntime/qv4regexpobject.cpp +++ b/src/qml/jsruntime/qv4regexpobject.cpp @@ -142,8 +142,9 @@ void RegExpObject::init(ExecutionEngine *engine) vtbl = &static_vtbl; type = Type_RegExpObject; - Property *lastIndexProperty = insertMember(engine->newIdentifier(QStringLiteral("lastIndex")), - Attr_NotEnumerable|Attr_NotConfigurable); + Scope scope(engine); + ScopedString lastIndex(scope, engine->newIdentifier(QStringLiteral("lastIndex"))); + Property *lastIndexProperty = insertMember(lastIndex, Attr_NotEnumerable|Attr_NotConfigurable); lastIndexProperty->value = Value::fromInt32(0); if (!this->value) return; diff --git a/src/qml/jsruntime/qv4runtime.cpp b/src/qml/jsruntime/qv4runtime.cpp index f440ade430..c01f172eb3 100644 --- a/src/qml/jsruntime/qv4runtime.cpp +++ b/src/qml/jsruntime/qv4runtime.cpp @@ -619,14 +619,14 @@ Returned<String> *__qmljs_convert_to_string(ExecutionContext *ctx, const ValueRe case Value::Empty_Type: Q_ASSERT(!"empty Value encountered"); case Value::Undefined_Type: - return ctx->engine->id_undefined->asReturned<String>(); + return ctx->engine->id_undefined; case Value::Null_Type: - return ctx->engine->id_null->asReturned<String>(); + return ctx->engine->id_null; case Value::Boolean_Type: if (value->booleanValue()) - return ctx->engine->id_true->asReturned<String>(); + return ctx->engine->id_true; else - return ctx->engine->id_false->asReturned<String>(); + return ctx->engine->id_false; case Value::Managed_Type: if (value->isString()) return value->stringValue()->asReturned<String>(); @@ -1151,11 +1151,12 @@ void __qmljs_builtin_declare_var(ExecutionContext *ctx, bool deletable, String * void __qmljs_builtin_define_property(ExecutionContext *ctx, const ValueRef object, String *name, ValueRef val) { - Object *o = object->asObject(); + Scope scope(ctx); + ScopedObject o(scope, object->asObject()); assert(o); uint idx = name->asArrayIndex(); - Property *pd = (idx != UINT_MAX) ? o->arrayInsert(idx) : o->insertMember(name, Attr_Data); + Property *pd = (idx != UINT_MAX) ? o->arrayInsert(idx) : o->insertMember(ScopedString(scope, name), Attr_Data); pd->value = val ? *val : Value::undefinedValue(); } @@ -1187,11 +1188,12 @@ ReturnedValue __qmljs_builtin_define_array(ExecutionContext *ctx, Value *values, void __qmljs_builtin_define_getter_setter(ExecutionContext *ctx, const ValueRef object, String *name, const ValueRef getter, const ValueRef setter) { - Object *o = object->asObject(); - assert(o); + Scope scope(ctx); + ScopedObject o(scope, object->asObject()); + Q_ASSERT(!!o); uint idx = name->asArrayIndex(); - Property *pd = (idx != UINT_MAX) ? o->arrayInsert(idx, Attr_Accessor) : o->insertMember(name, Attr_Accessor); + Property *pd = (idx != UINT_MAX) ? o->arrayInsert(idx, Attr_Accessor) : o->insertMember(ScopedString(scope, name), Attr_Accessor); pd->setGetter(getter ? getter->asFunctionObject() : 0); pd->setSetter(setter ? setter->asFunctionObject() : 0); } diff --git a/src/qml/jsruntime/qv4scopedvalue_p.h b/src/qml/jsruntime/qv4scopedvalue_p.h index 68299c2e65..58bad216fa 100644 --- a/src/qml/jsruntime/qv4scopedvalue_p.h +++ b/src/qml/jsruntime/qv4scopedvalue_p.h @@ -367,6 +367,7 @@ struct ValueRef { : ptr(&v.d->value) {} ValueRef(PersistentValuePrivate *p) : ptr(&p->value) {} + ValueRef(SafeValue &v) { ptr = &v; } // Important: Do NOT add a copy constructor to this class // adding a copy constructor actually changes the calling convention, ie. // is not even binary compatible. Adding it would break assumptions made @@ -420,6 +421,7 @@ struct Referenced { // in the jit'ed code. Referenced(const Scoped<T> &v) : ptr(v.ptr) {} + Referenced(Safe<T> &v) { ptr = &v; } Referenced &operator=(const Referenced &o) { *ptr = *o.ptr; return *this; } Referenced &operator=(T *t) @@ -572,6 +574,41 @@ inline Returned<T> *SafeValue::as() } template<typename T> +inline Safe<T> &Safe<T>::operator =(T *t) +{ + val = t->asReturnedValue(); + return *this; +} + +template<typename T> +inline Safe<T> &Safe<T>::operator =(const Scoped<T> &v) +{ + val = v.ptr->val; + return *this; +} + +template<typename T> +inline Safe<T> &Safe<T>::operator=(Returned<T> *t) +{ + val = t->getPointer()->asReturnedValue(); + return *this; +} + +template<typename T> +inline Safe<T> &Safe<T>::operator=(const Safe<T> &t) +{ + val = t.val; + return *this; +} + +template<typename T> +inline Safe<T>::operator Returned<T> *() +{ + return Returned<T>::create(static_cast<T *>(managed())); +} + + +template<typename T> PersistentValue::PersistentValue(Returned<T> *obj) : d(new PersistentValuePrivate(QV4::Value::fromManaged(obj->getPointer()))) { diff --git a/src/qml/jsruntime/qv4value_def_p.h b/src/qml/jsruntime/qv4value_def_p.h index 7d97d4531e..3e0728bcc2 100644 --- a/src/qml/jsruntime/qv4value_def_p.h +++ b/src/qml/jsruntime/qv4value_def_p.h @@ -361,6 +361,22 @@ struct SafeValue : public Value Returned<T> *as(); }; +template <typename T> +struct Safe : public Value +{ + Safe &operator =(T *t); + Safe &operator =(const Scoped<T> &v); + Safe &operator =(Returned<T> *t); + Safe &operator =(const Safe<T> &t); + + // ### GC: remove me + operator T*() { return static_cast<T *>(managed()); } + Value *operator->() { return this; } + operator Returned<T> *(); +}; +typedef Safe<String> SafeString; +typedef Safe<Object> SafeObject; + template<typename T> T *value_cast(const Value &v) { diff --git a/src/qml/qml/v8/qv8engine.cpp b/src/qml/qml/v8/qv8engine.cpp index 73ad2807b5..38c0902a7e 100644 --- a/src/qml/qml/v8/qv8engine.cpp +++ b/src/qml/qml/v8/qv8engine.cpp @@ -569,8 +569,10 @@ QV4::ReturnedValue QV8Engine::variantMapToJS(const QVariantMap &vmap) QV4::Scope scope(m_v4Engine); QV4::Scoped<QV4::Object> o(scope, m_v4Engine->newObject()); QVariantMap::const_iterator it; + QV4::ScopedString s(scope); for (it = vmap.constBegin(); it != vmap.constEnd(); ++it) { - QV4::Property *p = o->insertMember(m_v4Engine->newIdentifier(it.key()), QV4::Attr_Data); + s = m_v4Engine->newIdentifier(it.key()); + QV4::Property *p = o->insertMember(s, QV4::Attr_Data); p->value = QV4::Value::fromReturnedValue(variantToJS(it.value())); } return o.asReturnedValue(); diff --git a/src/qml/types/qqmldelegatemodel.cpp b/src/qml/types/qqmldelegatemodel.cpp index c4b6141335..2e739bfcce 100644 --- a/src/qml/types/qqmldelegatemodel.cpp +++ b/src/qml/types/qqmldelegatemodel.cpp @@ -1629,34 +1629,37 @@ void QQmlDelegateModelItemMetaType::initializePrototype() QV4::Scoped<QV4::Object> proto(scope, v4->newObject()); proto->defineAccessorProperty(v4, QStringLiteral("model"), QQmlDelegateModelItem::get_model, 0); proto->defineAccessorProperty(v4, QStringLiteral("groups"), QQmlDelegateModelItem::get_groups, QQmlDelegateModelItem::set_groups); - QV4::Property *p = proto->insertMember(v4->newString(QStringLiteral("isUnresolved")), - QV4::Attr_Accessor|QV4::Attr_NotConfigurable|QV4::Attr_NotEnumerable); + QV4::ScopedString s(scope); + s = v4->newString(QStringLiteral("isUnresolved")); + QV4::Property *p = proto->insertMember(s, QV4::Attr_Accessor|QV4::Attr_NotConfigurable|QV4::Attr_NotEnumerable); p->setGetter(new (v4->memoryManager) DelegateModelGroupFunction(v4->rootContext, 30, QQmlDelegateModelItem::get_member)); - p = proto->insertMember(v4->newString(QStringLiteral("inItems")), - QV4::Attr_Accessor|QV4::Attr_NotConfigurable|QV4::Attr_NotEnumerable); + s = v4->newString(QStringLiteral("inItems")); + p = proto->insertMember(s, QV4::Attr_Accessor|QV4::Attr_NotConfigurable|QV4::Attr_NotEnumerable); p->setGetter(new (v4->memoryManager) DelegateModelGroupFunction(v4->rootContext, QQmlListCompositor::Default, QQmlDelegateModelItem::get_member)); p->setSetter(new (v4->memoryManager) DelegateModelGroupFunction(v4->rootContext, QQmlListCompositor::Default, QQmlDelegateModelItem::set_member)); - p = proto->insertMember(v4->newString(QStringLiteral("inPersistedItems")), - QV4::Attr_Accessor|QV4::Attr_NotConfigurable|QV4::Attr_NotEnumerable); + s = v4->newString(QStringLiteral("inPersistedItems")); + p = proto->insertMember(s, QV4::Attr_Accessor|QV4::Attr_NotConfigurable|QV4::Attr_NotEnumerable); p->setGetter(new (v4->memoryManager) DelegateModelGroupFunction(v4->rootContext, QQmlListCompositor::Persisted, QQmlDelegateModelItem::get_member)); p->setSetter(new (v4->memoryManager) DelegateModelGroupFunction(v4->rootContext, QQmlListCompositor::Persisted, QQmlDelegateModelItem::set_member)); - p = proto->insertMember(v4->newString(QStringLiteral("itemsIndex")), - QV4::Attr_Accessor|QV4::Attr_NotConfigurable|QV4::Attr_NotEnumerable); + s = v4->newString(QStringLiteral("itemsIndex")); + p = proto->insertMember(s, QV4::Attr_Accessor|QV4::Attr_NotConfigurable|QV4::Attr_NotEnumerable); p->setGetter(new (v4->memoryManager) DelegateModelGroupFunction(v4->rootContext, QQmlListCompositor::Default, QQmlDelegateModelItem::get_index)); - p = proto->insertMember(v4->newString(QStringLiteral("persistedItemsIndex")), - QV4::Attr_Accessor|QV4::Attr_NotConfigurable|QV4::Attr_NotEnumerable); + s = v4->newString(QStringLiteral("persistedItemsIndex")); + p = proto->insertMember(s, QV4::Attr_Accessor|QV4::Attr_NotConfigurable|QV4::Attr_NotEnumerable); p->setGetter(new (v4->memoryManager) DelegateModelGroupFunction(v4->rootContext, QQmlListCompositor::Persisted, QQmlDelegateModelItem::get_index)); for (int i = 2; i < groupNames.count(); ++i) { QString propertyName = QStringLiteral("in") + groupNames.at(i); propertyName.replace(2, 1, propertyName.at(2).toUpper()); - p = proto->insertMember(v4->newString(propertyName), QV4::Attr_Accessor|QV4::Attr_NotConfigurable|QV4::Attr_NotEnumerable); + s = v4->newString(propertyName); + p = proto->insertMember(s, QV4::Attr_Accessor|QV4::Attr_NotConfigurable|QV4::Attr_NotEnumerable); p->setGetter(new (v4->memoryManager) DelegateModelGroupFunction(v4->rootContext, i + 1, QQmlDelegateModelItem::get_member)); p->setSetter(new (v4->memoryManager) DelegateModelGroupFunction(v4->rootContext, i + 1, QQmlDelegateModelItem::set_member)); } for (int i = 2; i < groupNames.count(); ++i) { const QString propertyName = groupNames.at(i) + QStringLiteral("Index"); - p = proto->insertMember(v4->newString(propertyName), QV4::Attr_Accessor|QV4::Attr_NotConfigurable|QV4::Attr_NotEnumerable); + s = v4->newString(propertyName); + p = proto->insertMember(s, QV4::Attr_Accessor|QV4::Attr_NotConfigurable|QV4::Attr_NotEnumerable); p->setGetter(new (v4->memoryManager) DelegateModelGroupFunction(v4->rootContext, i + 1, QQmlDelegateModelItem::get_index)); } modelItemProto = proto; diff --git a/src/qml/util/qqmladaptormodel.cpp b/src/qml/util/qqmladaptormodel.cpp index 51d6b3c4da..4b1c30d4d2 100644 --- a/src/qml/util/qqmladaptormodel.cpp +++ b/src/qml/util/qqmladaptormodel.cpp @@ -223,8 +223,8 @@ public: const int propertyId = propertyRoles.indexOf(it.value()); const QByteArray &propertyName = it.key(); - QV4::Property *p = proto->insertMember(v4->newString(QString::fromUtf8(propertyName)), - QV4::Attr_Accessor|QV4::Attr_NotEnumerable|QV4::Attr_NotConfigurable); + QV4::ScopedString name(scope, v4->newString(QString::fromUtf8(propertyName))); + QV4::Property *p = proto->insertMember(name, QV4::Attr_Accessor|QV4::Attr_NotEnumerable|QV4::Attr_NotConfigurable); p->setGetter(new (v4->memoryManager) QV4::IndexedBuiltinFunction(v4->rootContext, propertyId, QQmlDMCachedModelData::get_property)); p->setSetter(new (v4->memoryManager) QV4::IndexedBuiltinFunction(v4->rootContext, propertyId, QQmlDMCachedModelData::set_property)); } |