aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@digia.com>2014-05-08 15:32:31 +0200
committerSimon Hausmann <simon.hausmann@digia.com>2014-07-22 13:49:14 +0200
commit76f3a874f42a5fc689334fa371f386762e37cc78 (patch)
tree62f2880ce6e2c6209e559bdf591385037a8c5eb2 /src
parent519471a77a67bb72f4d0995db70a95f290b13c6a (diff)
Convert delegate model and indexed builtin function
Change-Id: Ic7d50aa472d6a1bafadb6641f88b5f89a9b893ad Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src')
-rw-r--r--src/qml/jsruntime/qv4functionobject.cpp44
-rw-r--r--src/qml/jsruntime/qv4functionobject_p.h26
-rw-r--r--src/qml/jsruntime/qv4script.cpp3
-rw-r--r--src/qml/types/qqmldelegatemodel.cpp8
-rw-r--r--src/qml/types/qqmldelegatemodel_p_p.h15
-rw-r--r--src/qml/util/qqmladaptormodel.cpp10
6 files changed, 76 insertions, 30 deletions
diff --git a/src/qml/jsruntime/qv4functionobject.cpp b/src/qml/jsruntime/qv4functionobject.cpp
index 7fef9f700e..791ff0f3b3 100644
--- a/src/qml/jsruntime/qv4functionobject.cpp
+++ b/src/qml/jsruntime/qv4functionobject.cpp
@@ -74,6 +74,44 @@ using namespace QV4;
DEFINE_OBJECT_VTABLE(FunctionObject);
+FunctionObject::Data::Data(ExecutionContext *scope, String *name, bool createProto)
+ : Object::Data(scope->d()->engine->functionClass)
+ , scope(scope)
+{
+ Scope s(scope);
+ ScopedFunctionObject f(s, this);
+ f->init(name, createProto);
+}
+
+
+FunctionObject::Data::Data(ExecutionContext *scope, const QString &name, bool createProto)
+ : Object::Data(scope->d()->engine->functionClass)
+ , scope(scope)
+{
+ Scope s(scope);
+ ScopedFunctionObject f(s, this);
+ ScopedString n(s, s.engine->newString(name));
+ f->init(n.getPointer(), createProto);
+}
+
+FunctionObject::Data::Data(ExecutionContext *scope, const ReturnedValue name)
+ : Object::Data(scope->d()->engine->functionClass)
+ , scope(scope)
+{
+ Scope s(scope);
+ ScopedFunctionObject f(s, this);
+ ScopedString n(s, name);
+ f->init(n.getPointer(), false);
+}
+
+FunctionObject::Data::Data(InternalClass *ic)
+ : Object::Data(ic)
+ , scope(ic->engine->rootContext)
+{
+ memberData.ensureIndex(ic->engine, Index_Prototype);
+ memberData[Index_Prototype] = Encode::undefined();
+}
+
FunctionObject::FunctionObject(ExecutionContext *scope, String *name, bool createProto)
: Object(scope->d()->engine->functionClass)
{
@@ -117,10 +155,10 @@ FunctionObject::FunctionObject(InternalClass *ic)
memberData()[Index_Prototype] = Encode::undefined();
}
-FunctionObject::~FunctionObject()
+FunctionObject::Data::~Data()
{
- if (function())
- function()->compilationUnit->deref();
+ if (function)
+ function->compilationUnit->deref();
}
void FunctionObject::init(String *n, bool createProto)
diff --git a/src/qml/jsruntime/qv4functionobject_p.h b/src/qml/jsruntime/qv4functionobject_p.h
index 824743bbb3..b5cc315666 100644
--- a/src/qml/jsruntime/qv4functionobject_p.h
+++ b/src/qml/jsruntime/qv4functionobject_p.h
@@ -95,9 +95,14 @@ struct Lookup;
struct Q_QML_EXPORT FunctionObject: Object {
struct Data : Object::Data {
+ Data(ExecutionContext *scope, String *name, bool createProto = false);
+ Data(ExecutionContext *scope, const QString &name = QString(), bool createProto = false);
+ Data(ExecutionContext *scope, const ReturnedValue name);
+ Data(InternalClass *ic);
+ ~Data();
+
ExecutionContext *scope;
Function *function;
-
};
struct {
ExecutionContext *scope;
@@ -132,7 +137,6 @@ struct Q_QML_EXPORT FunctionObject: Object {
FunctionObject(ExecutionContext *scope, String *name, bool createProto = false);
FunctionObject(ExecutionContext *scope, const QString &name = QString(), bool createProto = false);
FunctionObject(ExecutionContext *scope, const ReturnedValue name);
- ~FunctionObject();
void init(String *name, bool createProto);
@@ -142,6 +146,9 @@ struct Q_QML_EXPORT FunctionObject: Object {
using Object::call;
static ReturnedValue construct(Managed *that, CallData *);
static ReturnedValue call(Managed *that, CallData *d);
+ static void destroy(Managed *m) {
+ static_cast<FunctionObject *>(m)->d()->~Data();
+ }
static FunctionObject *cast(const Value &v) {
return v.asFunctionObject();
@@ -204,6 +211,13 @@ struct BuiltinFunction: FunctionObject {
struct IndexedBuiltinFunction: FunctionObject
{
struct Data : FunctionObject::Data {
+ Data(ExecutionContext *scope, uint index, ReturnedValue (*code)(CallContext *ctx, uint index))
+ : FunctionObject::Data(scope),
+ code(code)
+ , index(index)
+ {
+ setVTable(staticVTable());
+ }
ReturnedValue (*code)(CallContext *, uint index);
uint index;
};
@@ -213,14 +227,6 @@ struct IndexedBuiltinFunction: FunctionObject
} __data;
V4_OBJECT
- IndexedBuiltinFunction(ExecutionContext *scope, uint index, ReturnedValue (*code)(CallContext *ctx, uint index))
- : FunctionObject(scope)
- {
- d()->code = code;
- d()->index = index;
- setVTable(staticVTable());
- }
-
static ReturnedValue construct(Managed *m, CallData *)
{
return m->engine()->currentContext()->throwTypeError();
diff --git a/src/qml/jsruntime/qv4script.cpp b/src/qml/jsruntime/qv4script.cpp
index 6627aa216b..af25f6aec2 100644
--- a/src/qml/jsruntime/qv4script.cpp
+++ b/src/qml/jsruntime/qv4script.cpp
@@ -152,7 +152,8 @@ Returned<FunctionObject> *QmlBindingWrapper::createQmlCallableForFunction(QQmlCo
QV4::ScopedString s(valueScope);
int index = 0;
foreach (const QByteArray &param, signalParameters) {
- p->setGetter(new (engine->memoryManager) QV4::IndexedBuiltinFunction(wrapper->context(), index++, signalParameterGetter));
+ QV4::ScopedFunctionObject g(valueScope, new (engine) QV4::IndexedBuiltinFunction::Data(wrapper->context(), index++, signalParameterGetter));
+ p->setGetter(g);
p->setSetter(0);
s = engine->newString(QString::fromUtf8(param));
qmlScopeObject->insertMember(s.getPointer(), p, QV4::Attr_Accessor|QV4::Attr_NotEnumerable|QV4::Attr_NotConfigurable);
diff --git a/src/qml/types/qqmldelegatemodel.cpp b/src/qml/types/qqmldelegatemodel.cpp
index 14518bfe6c..8c3243a4f5 100644
--- a/src/qml/types/qqmldelegatemodel.cpp
+++ b/src/qml/types/qqmldelegatemodel.cpp
@@ -1857,14 +1857,14 @@ QV4::ReturnedValue QQmlDelegateModelItem::get_index(QQmlDelegateModelItem *thisI
DEFINE_OBJECT_VTABLE(QQmlDelegateModelItemObject);
-QQmlDelegateModelItemObject::~QQmlDelegateModelItemObject()
+QQmlDelegateModelItemObject::Data::~Data()
{
- d()->item->Dispose();
+ item->Dispose();
}
void QQmlDelegateModelItemObject::destroy(Managed *that)
{
- static_cast<QQmlDelegateModelItemObject *>(that)->~QQmlDelegateModelItemObject();
+ static_cast<QQmlDelegateModelItemObject *>(that)->d()->~Data();
}
@@ -2466,7 +2466,7 @@ QQmlV4Handle QQmlDelegateModelGroup::get(int index)
QV8Engine *v8 = model->m_cacheMetaType->v8Engine;
QV4::ExecutionEngine *v4 = QV8Engine::getV4(v8);
QV4::Scope scope(v4);
- QV4::ScopedObject o(scope, new (v4->memoryManager) QQmlDelegateModelItemObject(v4, cacheItem));
+ QV4::ScopedObject o(scope, new (v4) QQmlDelegateModelItemObject::Data(v4, cacheItem));
QV4::ScopedObject p(scope, model->m_cacheMetaType->modelItemProto.value());
o->setPrototype(p.getPointer());
++cacheItem->scriptRef;
diff --git a/src/qml/types/qqmldelegatemodel_p_p.h b/src/qml/types/qqmldelegatemodel_p_p.h
index 652c772aa5..e305ac1f3a 100644
--- a/src/qml/types/qqmldelegatemodel_p_p.h
+++ b/src/qml/types/qqmldelegatemodel_p_p.h
@@ -162,6 +162,13 @@ protected:
struct QQmlDelegateModelItemObject : QV4::Object
{
struct Data : QV4::Object::Data {
+ Data(QV4::ExecutionEngine *engine, QQmlDelegateModelItem *item)
+ : Object::Data(engine)
+ , item(item)
+ {
+ setVTable(staticVTable());
+ }
+ ~Data();
QQmlDelegateModelItem *item;
};
struct {
@@ -170,14 +177,6 @@ struct QQmlDelegateModelItemObject : QV4::Object
V4_OBJECT
- QQmlDelegateModelItemObject(QV4::ExecutionEngine *engine, QQmlDelegateModelItem *item)
- : Object(engine)
- {
- setVTable(staticVTable());
- d()->item = item;
- }
- ~QQmlDelegateModelItemObject();
-
static void destroy(Managed *that);
};
diff --git a/src/qml/util/qqmladaptormodel.cpp b/src/qml/util/qqmladaptormodel.cpp
index 446020d36b..d33000559b 100644
--- a/src/qml/util/qqmladaptormodel.cpp
+++ b/src/qml/util/qqmladaptormodel.cpp
@@ -227,8 +227,10 @@ public:
const QByteArray &propertyName = it.key();
QV4::ScopedString name(scope, v4->newString(QString::fromUtf8(propertyName)));
- 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));
+ QV4::ScopedFunctionObject g(scope, new (v4) QV4::IndexedBuiltinFunction::Data(v4->rootContext, propertyId, QQmlDMCachedModelData::get_property));
+ QV4::ScopedFunctionObject s(scope, new (v4) QV4::IndexedBuiltinFunction::Data(v4->rootContext, propertyId, QQmlDMCachedModelData::set_property));
+ p->setGetter(g);
+ p->setSetter(s);
proto->insertMember(name.getPointer(), p, QV4::Attr_Accessor|QV4::Attr_NotEnumerable|QV4::Attr_NotConfigurable);
}
prototype = proto;
@@ -431,7 +433,7 @@ public:
}
QV4::Scope scope(v4);
QV4::ScopedObject proto(scope, type->prototype.value());
- QV4::ScopedObject o(scope, new (proto->engine()->memoryManager) QQmlDelegateModelItemObject(proto->engine(), this));
+ QV4::ScopedObject o(scope, new (proto->engine()) QQmlDelegateModelItemObject::Data(proto->engine(), this));
o->setPrototype(proto.getPointer());
++scriptRef;
return o.asReturnedValue();
@@ -609,7 +611,7 @@ public:
{
QQmlAdaptorModelEngineData *data = engineData(v4->v8Engine);
QV4::Scope scope(v4);
- QV4::ScopedObject o(scope, new (v4->memoryManager) QQmlDelegateModelItemObject(v4, this));
+ QV4::ScopedObject o(scope, new (v4) QQmlDelegateModelItemObject::Data(v4, this));
QV4::ScopedObject p(scope, data->listItemProto.value());
o->setPrototype(p.getPointer());
++scriptRef;