From e45012ac724a637f2b1293082b033b5dd94e18a9 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Thu, 13 Jun 2013 12:52:41 +0200 Subject: [PATCH] Get rid of memberAccessorGetter The new defineAccessorProperty is much simpler, so change v4classgen to generate that. Change-Id: I5578ef33c2e1735933ec6f10a23e3a69db9b1984 Reviewed-by: Lars Knoll --- src/qml/qml/v4/qv4functionobject.cpp | 31 ------------------------------- src/qml/qml/v4/qv4functionobject_p.h | 20 -------------------- src/qml/qml/v4/v4classgen | 25 ++++++------------------- 3 files changed, 6 insertions(+), 70 deletions(-) diff --git a/src/qml/qml/v4/qv4functionobject.cpp b/src/qml/qml/v4/qv4functionobject.cpp index 604b559..b339805 100644 --- a/src/qml/qml/v4/qv4functionobject.cpp +++ b/src/qml/qml/v4/qv4functionobject.cpp @@ -543,34 +543,3 @@ void BoundFunction::markObjects(Managed *that) m->mark(); FunctionObject::markObjects(that); } - - -Value MemberAccessorGetterSetter::call(Managed *that, ExecutionContext *context, const Value &thisObject, Value *args, int argc) -{ - MemberAccessorGetterSetter *getterSetter = static_cast(that); - - Object *thisO = thisObject.asObject(); - if (!thisO || thisO->internalType() != getterSetter->managedType) - context->throwTypeError(); - - QV4::SimpleCallContext ctx; - ctx.initSimpleCallContext(context->engine); - ctx.strictMode = true; - ctx.thisObject = thisObject; - ctx.arguments = args; - ctx.argumentCount = argc; - context->engine->pushContext(&ctx); - - QV4::Value result = QV4::Value::undefinedValue(); - try { - result = getterSetter->getterSetter(&ctx); - } catch (QV4::Exception &ex) { - ex.partiallyUnwindContext(context); - throw; - } - context->engine->popContext(); - return result; -} - - -DEFINE_MANAGED_VTABLE(MemberAccessorGetterSetter); diff --git a/src/qml/qml/v4/qv4functionobject_p.h b/src/qml/qml/v4/qv4functionobject_p.h index 683112c..0c361bf 100644 --- a/src/qml/qml/v4/qv4functionobject_p.h +++ b/src/qml/qml/v4/qv4functionobject_p.h @@ -223,26 +223,6 @@ struct BoundFunction: FunctionObject { static bool hasInstance(Managed *that, ExecutionContext *ctx, const Value &value); }; -class Q_QML_EXPORT MemberAccessorGetterSetter : public FunctionObject -{ -public: - typedef Value (* GetterSetterFunction)(QV4::SimpleCallContext *ctx); - - MemberAccessorGetterSetter(ExecutionContext *scope, GetterSetterFunction getterSetter, int managedType) - : FunctionObject(scope) - , managedType(managedType) - { - this->vtbl = &static_vtbl; - this->getterSetter = getterSetter; - } - - static QV4::Value call(Managed *that, ExecutionContext *context, const QV4::Value &thisObject, QV4::Value *args, int argc); -protected: - GetterSetterFunction getterSetter; - const int managedType; - static const ManagedVTable static_vtbl; -}; - } QT_END_NAMESPACE diff --git a/src/qml/qml/v4/v4classgen b/src/qml/qml/v4/v4classgen index 614124f..82d6dbf 100755 --- a/src/qml/qml/v4/v4classgen +++ b/src/qml/qml/v4/v4classgen @@ -84,28 +84,15 @@ class Accessor(): managedType = "type" if len(obj) > 0: managedType = obj + "internalType()" - out.write(" {\n") - out.write(" QV4::FunctionObject *wrappedGetter = 0;\n") - out.write(" QV4::FunctionObject *wrappedSetter = 0;\n") - out.write("\n") + + getter = "0" if self.getter: - out.write(" wrappedGetter = new (engine->memoryManager) QV4::MemberAccessorGetterSetter(engine->rootContext, &%s::%s, %s);\n" % (parsedClass.name, self.getter.fullMethodName(), managedType)) + getter = "%s::%s" % (parsedClass.name, self.getter.fullMethodName()) + setter = "0" if self.setter: - out.write(" wrappedSetter = new (engine->memoryManager) QV4::MemberAccessorGetterSetter(engine->rootContext, &%s::%s, %s);\n" % (parsedClass.name, self.setter.fullMethodName(), managedType)) - - attributes = ["QV4::Attr_Accessor"]; - - if self.getter and "attributes" in self.getter.options: - attributes = attributes + [self.getter.options["attributes"]] - if self.setter and "attributes" in self.setter.options: - attributes = attributes + [self.setter.options["attributes"]] - - out.write(" QV4::PropertyAttributes attrs = %s;\n" % "|".join(attributes)) + setter = "%s::%s" % (parsedClass.name, self.setter.fullMethodName()) - out.write(" QV4::Property *pd = %sinsertMember(engine->newIdentifier(QStringLiteral(\"%s\")), attrs);\n" % (obj, self.name)); - out.write(" pd->setGetter(wrappedGetter);\n"); - out.write(" pd->setSetter(wrappedSetter);\n"); - out.write(" }\n"); + out.write(" %sdefineAccessorProperty(engine, QStringLiteral(\"%s\"), %s, %s);\n" % (obj, self.name, getter, setter)) def parseOptions(options): options = options.split(" ") -- 2.7.4