diff options
author | Lars Knoll <lars.knoll@digia.com> | 2013-09-13 14:11:55 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-09-18 13:14:03 +0200 |
commit | 49aead7f236f8b8a6ab85adc4b5eace1c1e4dde6 (patch) | |
tree | 21b01c30b568bd79176a5dfe4ec2437e2545660e /src/qml/jsruntime/qv4runtime.cpp | |
parent | 2a43ec129a544d80c9cc3266b5eccce0f6ba66ef (diff) |
Extend the ReturnedValue mechanism to pointers to Managed objects
Add a Returned<T> that we can return instead of raw pointers
to Managed objects.
Start using the Returned<T> for a few methods.
Also clean up all our classes to use the Q_MANAGED macro instead
of manually defining their vtable.
Change-Id: I0a2962e47f3de955cd2cd8474f8f3fcc9e36d084
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src/qml/jsruntime/qv4runtime.cpp')
-rw-r--r-- | src/qml/jsruntime/qv4runtime.cpp | 38 |
1 files changed, 27 insertions, 11 deletions
diff --git a/src/qml/jsruntime/qv4runtime.cpp b/src/qml/jsruntime/qv4runtime.cpp index 0a8b1b4055..cfb0a9f4a0 100644 --- a/src/qml/jsruntime/qv4runtime.cpp +++ b/src/qml/jsruntime/qv4runtime.cpp @@ -598,7 +598,7 @@ Bool __qmljs_to_boolean(const ValueRef value) } -Object *__qmljs_convert_to_object(ExecutionContext *ctx, const ValueRef value) +Returned<Object> *__qmljs_convert_to_object(ExecutionContext *ctx, const ValueRef value) { assert(!value->isObject()); switch (value->type()) { @@ -608,7 +608,7 @@ Object *__qmljs_convert_to_object(ExecutionContext *ctx, const ValueRef value) case Value::Boolean_Type: return ctx->engine->newBooleanObject(*value); case Value::String_Type: - return ctx->engine->newStringObject(*value); + return ctx->engine->newStringObject(*value)->asReturned<Object>(); break; case Value::Object_Type: Q_UNREACHABLE(); @@ -658,9 +658,10 @@ void __qmljs_set_property(ExecutionContext *ctx, const ValueRef object, String * ReturnedValue __qmljs_get_element(ExecutionContext *ctx, const ValueRef object, const ValueRef index) { + Scope scope(ctx); uint idx = index->asArrayIndex(); - Object *o = object->asObject(); + Scoped<Object> o(scope, object); if (!o) { if (idx < UINT_MAX) { if (String *str = object->asString()) { @@ -766,18 +767,19 @@ void __qmljs_set_activation_property(ExecutionContext *ctx, String *name, const ReturnedValue __qmljs_get_property(ExecutionContext *ctx, const ValueRef object, String *name) { - Value res; - Managed *m = object->asManaged(); - if (m) - return m->get(name); + Scope scope(ctx); + + Scoped<Object> o(scope, object); + if (o) + return o->get(name); if (object->isNullOrUndefined()) { QString message = QStringLiteral("Cannot read property '%1' of %2").arg(name->toQString()).arg(object->toQStringNoThrow()); ctx->throwTypeError(message); } - m = __qmljs_convert_to_object(ctx, object); - return m->get(name); + o = __qmljs_convert_to_object(ctx, object); + return o->get(name); } ReturnedValue __qmljs_get_activation_property(ExecutionContext *ctx, String *name) @@ -974,7 +976,7 @@ ReturnedValue __qmljs_call_activation_property(ExecutionContext *context, String ReturnedValue __qmljs_call_property(ExecutionContext *context, String *name, CallDataRef callData) { Scope scope(context); - Managed *baseObject = callData->thisObject.asManaged(); + Scoped<Object> baseObject(scope, callData->thisObject); if (!baseObject) { if (callData->thisObject.isNullOrUndefined()) { QString message = QStringLiteral("Cannot call method '%1' of %2").arg(name->toQString()).arg(callData->thisObject.toQStringNoThrow()); @@ -982,7 +984,7 @@ ReturnedValue __qmljs_call_property(ExecutionContext *context, String *name, Cal } baseObject = __qmljs_convert_to_object(context, ValueRef(&callData->thisObject)); - callData->thisObject = Value::fromObject(static_cast<Object *>(baseObject)); + callData->thisObject = baseObject.asValue(); } Scoped<FunctionObject> o(scope, baseObject->get(name)); @@ -1251,6 +1253,20 @@ QV4::ReturnedValue __qmljs_decrement(const QV4::ValueRef value) } } +QV4::ReturnedValue __qmljs_to_string(const QV4::ValueRef value, QV4::ExecutionContext *ctx) +{ + if (value->isString()) + return value.asReturnedValue(); + return __qmljs_convert_to_string(ctx, value)->asReturnedValue(); +} + +QV4::ReturnedValue __qmljs_to_object(QV4::ExecutionContext *ctx, const QV4::ValueRef value) +{ + if (value->isObject()) + return value.asReturnedValue(); + return Encode(__qmljs_convert_to_object(ctx, value)); +} + void __qmljs_value_to_double(double *result, const ValueRef value) { *result = value->toNumber(); |