diff options
author | Lars Knoll <lars.knoll@digia.com> | 2013-10-10 16:17:28 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-10-11 08:56:26 +0200 |
commit | 40db24351b6a89a3fb30a4870afdf90a4b91663f (patch) | |
tree | 2fa70623d615cef347c4ad3f9e8422455abc4aa3 /src/qml/jsruntime | |
parent | b0e83cdc1a3a80ecc26cb31ac046b6c743238d41 (diff) |
Smaller cleanups
Change-Id: I0a7eee96ef7c92ad4a3c5963010e3ac66fe6ed3a
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src/qml/jsruntime')
-rw-r--r-- | src/qml/jsruntime/qv4argumentsobject.cpp | 8 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4booleanobject.cpp | 8 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4errorobject.cpp | 3 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4function.cpp | 3 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4functionobject.cpp | 6 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4mm.cpp | 7 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4numberobject.cpp | 1 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4object_p.h | 4 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4qobjectwrapper.cpp | 9 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4value.cpp | 5 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4value_def_p.h | 3 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4value_p.h | 5 |
12 files changed, 32 insertions, 30 deletions
diff --git a/src/qml/jsruntime/qv4argumentsobject.cpp b/src/qml/jsruntime/qv4argumentsobject.cpp index 70adb1f152..39d6954716 100644 --- a/src/qml/jsruntime/qv4argumentsobject.cpp +++ b/src/qml/jsruntime/qv4argumentsobject.cpp @@ -178,10 +178,8 @@ void ArgumentsObject::markObjects(Managed *that) { ArgumentsObject *o = static_cast<ArgumentsObject *>(that); o->context->mark(); - for (int i = 0; i < o->mappedArguments.size(); ++i) { - Managed *m = o->mappedArguments.at(i).asManaged(); - if (m) - m->mark(); - } + for (int i = 0; i < o->mappedArguments.size(); ++i) + o->mappedArguments.at(i).mark(); + Object::markObjects(that); } diff --git a/src/qml/jsruntime/qv4booleanobject.cpp b/src/qml/jsruntime/qv4booleanobject.cpp index 341e3003c6..d4d6201c01 100644 --- a/src/qml/jsruntime/qv4booleanobject.cpp +++ b/src/qml/jsruntime/qv4booleanobject.cpp @@ -44,6 +44,7 @@ using namespace QV4; DEFINE_MANAGED_VTABLE(BooleanCtor); +DEFINE_MANAGED_VTABLE(BooleanObject); BooleanCtor::BooleanCtor(ExecutionContext *scope) : FunctionObject(scope, QStringLiteral("Boolean")) @@ -82,7 +83,8 @@ ReturnedValue BooleanPrototype::method_toString(SimpleCallContext *ctx) if (ctx->callData->thisObject.isBoolean()) { result = ctx->callData->thisObject.booleanValue(); } else { - BooleanObject *thisObject = ctx->callData->thisObject.asBooleanObject(); + Scope scope(ctx); + Scoped<BooleanObject> thisObject(scope, ctx->callData->thisObject); if (!thisObject) ctx->throwTypeError(); result = thisObject->value.booleanValue(); @@ -93,7 +95,9 @@ ReturnedValue BooleanPrototype::method_toString(SimpleCallContext *ctx) ReturnedValue BooleanPrototype::method_valueOf(SimpleCallContext *ctx) { - BooleanObject *thisObject = ctx->callData->thisObject.asBooleanObject(); + // ### Shouldn't this work for a boolean thisObject? + Scope scope(ctx); + Scoped<BooleanObject> thisObject(scope, ctx->callData->thisObject); if (!thisObject) ctx->throwTypeError(); diff --git a/src/qml/jsruntime/qv4errorobject.cpp b/src/qml/jsruntime/qv4errorobject.cpp index 58375ea51e..ef9dc473f3 100644 --- a/src/qml/jsruntime/qv4errorobject.cpp +++ b/src/qml/jsruntime/qv4errorobject.cpp @@ -169,7 +169,8 @@ ErrorObject::ErrorObject(InternalClass *ic, const QString &message, const QStrin ReturnedValue ErrorObject::method_get_stack(SimpleCallContext *ctx) { - ErrorObject *This = ctx->callData->thisObject.asErrorObject(); + Scope scope(ctx); + Scoped<ErrorObject> This(scope, ctx->callData->thisObject); if (!This) ctx->throwTypeError(); if (!This->stack) { diff --git a/src/qml/jsruntime/qv4function.cpp b/src/qml/jsruntime/qv4function.cpp index dc2643b60a..65fec54be6 100644 --- a/src/qml/jsruntime/qv4function.cpp +++ b/src/qml/jsruntime/qv4function.cpp @@ -82,8 +82,7 @@ Function::~Function() void Function::mark() { - if (name.asManaged()) - name.asManaged()->mark(); + name.mark(); for (int i = 0; i < formals.size(); ++i) formals.at(i)->mark(); for (int i = 0; i < locals.size(); ++i) diff --git a/src/qml/jsruntime/qv4functionobject.cpp b/src/qml/jsruntime/qv4functionobject.cpp index 058c71f9f3..e67b3ef771 100644 --- a/src/qml/jsruntime/qv4functionobject.cpp +++ b/src/qml/jsruntime/qv4functionobject.cpp @@ -719,10 +719,8 @@ void BoundFunction::markObjects(Managed *that) { BoundFunction *o = static_cast<BoundFunction *>(that); o->target->mark(); - if (Managed *m = o->boundThis.asManaged()) - m->mark(); + o->boundThis.mark(); for (int i = 0; i < o->boundArgs.size(); ++i) - if (Managed *m = o->boundArgs.at(i).asManaged()) - m->mark(); + o->boundArgs.at(i).mark(); FunctionObject::markObjects(that); } diff --git a/src/qml/jsruntime/qv4mm.cpp b/src/qml/jsruntime/qv4mm.cpp index 59dd4e8625..81b9e1a053 100644 --- a/src/qml/jsruntime/qv4mm.cpp +++ b/src/qml/jsruntime/qv4mm.cpp @@ -332,8 +332,7 @@ void MemoryManager::mark() persistent = n; continue; } - if (Managed *m = persistent->value.asManaged()) - m->mark(); + persistent->value.mark(); persistent = persistent->next; } @@ -668,8 +667,8 @@ void MemoryManager::collectFromStack() const void MemoryManager::collectFromJSStack() const { - Value *v = engine()->jsStackBase; - Value *top = engine()->jsStackTop; + SafeValue *v = engine()->jsStackBase; + SafeValue *top = engine()->jsStackTop; while (v < top) { Managed *m = v->asManaged(); if (m && m->inUse) diff --git a/src/qml/jsruntime/qv4numberobject.cpp b/src/qml/jsruntime/qv4numberobject.cpp index 3ff4b795f5..8a09de5349 100644 --- a/src/qml/jsruntime/qv4numberobject.cpp +++ b/src/qml/jsruntime/qv4numberobject.cpp @@ -49,6 +49,7 @@ using namespace QV4; DEFINE_MANAGED_VTABLE(NumberCtor); +DEFINE_MANAGED_VTABLE(NumberObject); NumberCtor::NumberCtor(ExecutionContext *scope) : FunctionObject(scope, QStringLiteral("Number")) diff --git a/src/qml/jsruntime/qv4object_p.h b/src/qml/jsruntime/qv4object_p.h index 77f8d11e4f..032aadd5a6 100644 --- a/src/qml/jsruntime/qv4object_p.h +++ b/src/qml/jsruntime/qv4object_p.h @@ -329,9 +329,11 @@ private: }; struct BooleanObject: Object { + Q_MANAGED SafeValue value; BooleanObject(ExecutionEngine *engine, const ValueRef val) : Object(engine->booleanClass) { + vtbl = &static_vtbl; type = Type_BooleanObject; value = val; } @@ -344,9 +346,11 @@ protected: }; struct NumberObject: Object { + Q_MANAGED SafeValue value; NumberObject(ExecutionEngine *engine, const ValueRef val) : Object(engine->numberClass) { + vtbl = &static_vtbl; type = Type_NumberObject; value = val; } diff --git a/src/qml/jsruntime/qv4qobjectwrapper.cpp b/src/qml/jsruntime/qv4qobjectwrapper.cpp index 6e474ecc5d..d42d842ab7 100644 --- a/src/qml/jsruntime/qv4qobjectwrapper.cpp +++ b/src/qml/jsruntime/qv4qobjectwrapper.cpp @@ -1486,7 +1486,11 @@ void CallArgument::initAsType(int callType) void CallArgument::fromValue(int callType, QV8Engine *engine, const QV4::ValueRef value) { - if (type != 0) { cleanup(); type = 0; } + if (type != 0) { + cleanup(); + type = 0; + } + QV4::Scope scope(QV8Engine::getV4(engine)); if (callType == qMetaTypeId<QJSValue>()) { @@ -1524,7 +1528,8 @@ void CallArgument::fromValue(int callType, QV8Engine *engine, const QV4::ValueRe type = callType; } else if (callType == qMetaTypeId<QList<QObject*> >()) { qlistPtr = new (&allocData) QList<QObject *>(); - if (QV4::ArrayObject *array = value->asArrayObject()) { + QV4::ScopedArrayObject array(scope, value); + if (array) { Scoped<QV4::QObjectWrapper> qobjectWrapper(scope); uint32_t length = array->arrayLength(); diff --git a/src/qml/jsruntime/qv4value.cpp b/src/qml/jsruntime/qv4value.cpp index 318fb48768..ebd1894016 100644 --- a/src/qml/jsruntime/qv4value.cpp +++ b/src/qml/jsruntime/qv4value.cpp @@ -402,10 +402,7 @@ void WeakValue::markOnce() { if (!d) return; - Managed *m = d->value.asManaged(); - if (!m) - return; - m->mark(); + d->value.mark(); } PersistentValuePrivate::PersistentValuePrivate(ReturnedValue v, ExecutionEngine *e, bool weak) diff --git a/src/qml/jsruntime/qv4value_def_p.h b/src/qml/jsruntime/qv4value_def_p.h index 24d62cf54f..c8d03cfeed 100644 --- a/src/qml/jsruntime/qv4value_def_p.h +++ b/src/qml/jsruntime/qv4value_def_p.h @@ -312,7 +312,6 @@ struct Q_QML_EXPORT Value Managed *asManaged() const; Object *asObject() const; FunctionObject *asFunctionObject() const; - BooleanObject *asBooleanObject() const; NumberObject *asNumberObject() const; StringObject *asStringObject() const; DateObject *asDateObject() const; @@ -444,6 +443,8 @@ struct Safe : public SafeValue const T *operator->() const { return static_cast<T *>(managed()); } T *getPointer() const { return static_cast<T *>(managed()); } Returned<T> *ret() const; + + void mark() { if (managed()) managed()->mark(); } }; typedef Safe<String> SafeString; typedef Safe<Object> SafeObject; diff --git a/src/qml/jsruntime/qv4value_p.h b/src/qml/jsruntime/qv4value_p.h index 73450981a3..362f41affe 100644 --- a/src/qml/jsruntime/qv4value_p.h +++ b/src/qml/jsruntime/qv4value_p.h @@ -247,11 +247,6 @@ inline FunctionObject *Value::asFunctionObject() const return isObject() ? managed()->asFunctionObject() : 0; } -inline BooleanObject *Value::asBooleanObject() const -{ - return isObject() ? managed()->asBooleanObject() : 0; -} - inline NumberObject *Value::asNumberObject() const { return isObject() ? managed()->asNumberObject() : 0; |