Convert methods in qv4runtime to use Returned<X>

Change-Id: I1f68ecb298b049f3fa90de26b4b39233d48fb8e0
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
This commit is contained in:
Lars Knoll 2013-09-13 16:19:22 +02:00 committed by The Qt Project
parent 49aead7f23
commit 19f7850176
5 changed files with 21 additions and 27 deletions

View File

@ -68,6 +68,7 @@ struct Returned : private T
T *getPointer() { return this; }
template<typename X>
static T *getPointer(Returned<X> *x) { return x->getPointer(); }
using T::asReturnedValue;
};
#define Q_MANAGED \

View File

@ -196,7 +196,7 @@ ReturnedValue NumberPrototype::method_toFixed(SimpleCallContext *ctx)
else if (v < 1.e21)
str = QString::number(v, 'f', int (fdigits));
else
return __qmljs_string_from_number(ctx, v);
return __qmljs_string_from_number(ctx, v)->asReturnedValue();
return Value::fromString(ctx, str).asReturnedValue();
}

View File

@ -285,8 +285,7 @@ QV4::ReturnedValue __qmljs_add_helper(ExecutionContext *ctx, const ValueRef left
pleft = __qmljs_to_string(pleft, ctx);
if (!pright->isString())
pright = __qmljs_to_string(pright, ctx);
String *string = __qmljs_string_concat(ctx, pleft->stringValue(), pright->stringValue());
return Value::fromString(string).asReturnedValue();
return __qmljs_string_concat(ctx, pleft->stringValue(), pright->stringValue())->asReturnedValue();
}
double x = __qmljs_to_number(pleft);
double y = __qmljs_to_number(pright);
@ -532,15 +531,15 @@ double __qmljs_string_to_number(const QString &string)
return d;
}
ReturnedValue __qmljs_string_from_number(ExecutionContext *ctx, double number)
Returned<String> *__qmljs_string_from_number(ExecutionContext *ctx, double number)
{
QString qstr;
__qmljs_numberToString(&qstr, number, 10);
String *string = ctx->engine->newString(qstr);
return string->asReturnedValue();
return string->asReturned<String>();
}
String *__qmljs_string_concat(ExecutionContext *ctx, String *first, String *second)
Returned<String> *__qmljs_string_concat(ExecutionContext *ctx, String *first, String *second)
{
const QString &a = first->toQString();
const QString &b = second->toQString();
@ -550,7 +549,7 @@ String *__qmljs_string_concat(ExecutionContext *ctx, String *first, String *seco
data += a.length();
memcpy(data, b.constData(), b.length()*sizeof(QChar));
return ctx->engine->newString(newStr);
return ctx->engine->newString(newStr)->asReturned<String>();
}
ReturnedValue __qmljs_object_default_value(Object *object, int typeHint)
@ -618,35 +617,29 @@ Returned<Object> *__qmljs_convert_to_object(ExecutionContext *ctx, const ValueRe
}
}
String *__qmljs_convert_to_string(ExecutionContext *ctx, const ValueRef value)
Returned<String> *__qmljs_convert_to_string(ExecutionContext *ctx, const ValueRef value)
{
switch (value->type()) {
case Value::Undefined_Type:
return ctx->engine->id_undefined;
return ctx->engine->id_undefined->asReturned<String>();
case Value::Null_Type:
return ctx->engine->id_null;
return ctx->engine->id_null->asReturned<String>();
case Value::Boolean_Type:
if (value->booleanValue())
return ctx->engine->id_true;
return ctx->engine->id_true->asReturned<String>();
else
return ctx->engine->id_false;
return ctx->engine->id_false->asReturned<String>();
case Value::String_Type:
return value->stringValue();
return value->stringValue()->asReturned<String>();
case Value::Object_Type: {
Scope scope(ctx);
ScopedValue prim(scope, __qmljs_to_primitive(value, STRING_HINT));
return __qmljs_convert_to_string(ctx, prim);
}
case Value::Integer_Type: {
Scope scope(ctx);
ScopedValue dbl(scope, __qmljs_string_from_number(ctx, value->int_32));
return dbl->stringValue();
}
default: { // double
Scope scope(ctx);
ScopedValue dbl(scope, __qmljs_string_from_number(ctx, value->doubleValue()));
return dbl->stringValue();
}
case Value::Integer_Type:
return __qmljs_string_from_number(ctx, value->int_32);
default: // double
return __qmljs_string_from_number(ctx, value->doubleValue());
} // switch
}

View File

@ -143,8 +143,8 @@ QV4::ReturnedValue __qmljs_init_closure(QV4::ExecutionContext *ctx, int function
// strings
Q_QML_EXPORT double __qmljs_string_to_number(const QString &s);
QV4::ReturnedValue __qmljs_string_from_number(QV4::ExecutionContext *ctx, double number);
QV4::String *__qmljs_string_concat(QV4::ExecutionContext *ctx, QV4::String *first, QV4::String *second);
Returned<String> *__qmljs_string_from_number(QV4::ExecutionContext *ctx, double number);
Returned<String> *__qmljs_string_concat(QV4::ExecutionContext *ctx, QV4::String *first, QV4::String *second);
// objects
Q_QML_EXPORT ReturnedValue __qmljs_object_default_value(QV4::Object *object, int typeHint);
@ -169,7 +169,7 @@ QV4::ReturnedValue __qmljs_to_primitive(const ValueRef value, int typeHint);
Q_QML_EXPORT QV4::Bool __qmljs_to_boolean(const QV4::ValueRef value);
double __qmljs_to_number(const QV4::ValueRef value);
QV4::ReturnedValue __qmljs_to_string(const ValueRef value, QV4::ExecutionContext *ctx);
Q_QML_EXPORT QV4::String *__qmljs_convert_to_string(QV4::ExecutionContext *ctx, const ValueRef value);
Q_QML_EXPORT Returned<String> *__qmljs_convert_to_string(QV4::ExecutionContext *ctx, const ValueRef value);
void __qmljs_numberToString(QString *result, double num, int radix = 10);
ReturnedValue __qmljs_to_object(QV4::ExecutionContext *ctx, const ValueRef value);
Returned<Object> *__qmljs_convert_to_object(QV4::ExecutionContext *ctx, const ValueRef value);

View File

@ -305,7 +305,7 @@ String *Value::toString(ExecutionContext *ctx) const
{
if (isString())
return stringValue();
return __qmljs_convert_to_string(ctx, ValueRef::fromRawValue(this));
return __qmljs_convert_to_string(ctx, ValueRef::fromRawValue(this))->getPointer();
}
Object *Value::toObject(ExecutionContext *ctx) const