Convert methods in qv4runtime to use Returned<X>
Change-Id: I1f68ecb298b049f3fa90de26b4b39233d48fb8e0 Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
This commit is contained in:
parent
49aead7f23
commit
19f7850176
|
@ -68,6 +68,7 @@ struct Returned : private T
|
||||||
T *getPointer() { return this; }
|
T *getPointer() { return this; }
|
||||||
template<typename X>
|
template<typename X>
|
||||||
static T *getPointer(Returned<X> *x) { return x->getPointer(); }
|
static T *getPointer(Returned<X> *x) { return x->getPointer(); }
|
||||||
|
using T::asReturnedValue;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define Q_MANAGED \
|
#define Q_MANAGED \
|
||||||
|
|
|
@ -196,7 +196,7 @@ ReturnedValue NumberPrototype::method_toFixed(SimpleCallContext *ctx)
|
||||||
else if (v < 1.e21)
|
else if (v < 1.e21)
|
||||||
str = QString::number(v, 'f', int (fdigits));
|
str = QString::number(v, 'f', int (fdigits));
|
||||||
else
|
else
|
||||||
return __qmljs_string_from_number(ctx, v);
|
return __qmljs_string_from_number(ctx, v)->asReturnedValue();
|
||||||
return Value::fromString(ctx, str).asReturnedValue();
|
return Value::fromString(ctx, str).asReturnedValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -285,8 +285,7 @@ QV4::ReturnedValue __qmljs_add_helper(ExecutionContext *ctx, const ValueRef left
|
||||||
pleft = __qmljs_to_string(pleft, ctx);
|
pleft = __qmljs_to_string(pleft, ctx);
|
||||||
if (!pright->isString())
|
if (!pright->isString())
|
||||||
pright = __qmljs_to_string(pright, ctx);
|
pright = __qmljs_to_string(pright, ctx);
|
||||||
String *string = __qmljs_string_concat(ctx, pleft->stringValue(), pright->stringValue());
|
return __qmljs_string_concat(ctx, pleft->stringValue(), pright->stringValue())->asReturnedValue();
|
||||||
return Value::fromString(string).asReturnedValue();
|
|
||||||
}
|
}
|
||||||
double x = __qmljs_to_number(pleft);
|
double x = __qmljs_to_number(pleft);
|
||||||
double y = __qmljs_to_number(pright);
|
double y = __qmljs_to_number(pright);
|
||||||
|
@ -532,15 +531,15 @@ double __qmljs_string_to_number(const QString &string)
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnedValue __qmljs_string_from_number(ExecutionContext *ctx, double number)
|
Returned<String> *__qmljs_string_from_number(ExecutionContext *ctx, double number)
|
||||||
{
|
{
|
||||||
QString qstr;
|
QString qstr;
|
||||||
__qmljs_numberToString(&qstr, number, 10);
|
__qmljs_numberToString(&qstr, number, 10);
|
||||||
String *string = ctx->engine->newString(qstr);
|
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 &a = first->toQString();
|
||||||
const QString &b = second->toQString();
|
const QString &b = second->toQString();
|
||||||
|
@ -550,7 +549,7 @@ String *__qmljs_string_concat(ExecutionContext *ctx, String *first, String *seco
|
||||||
data += a.length();
|
data += a.length();
|
||||||
memcpy(data, b.constData(), b.length()*sizeof(QChar));
|
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)
|
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()) {
|
switch (value->type()) {
|
||||||
case Value::Undefined_Type:
|
case Value::Undefined_Type:
|
||||||
return ctx->engine->id_undefined;
|
return ctx->engine->id_undefined->asReturned<String>();
|
||||||
case Value::Null_Type:
|
case Value::Null_Type:
|
||||||
return ctx->engine->id_null;
|
return ctx->engine->id_null->asReturned<String>();
|
||||||
case Value::Boolean_Type:
|
case Value::Boolean_Type:
|
||||||
if (value->booleanValue())
|
if (value->booleanValue())
|
||||||
return ctx->engine->id_true;
|
return ctx->engine->id_true->asReturned<String>();
|
||||||
else
|
else
|
||||||
return ctx->engine->id_false;
|
return ctx->engine->id_false->asReturned<String>();
|
||||||
case Value::String_Type:
|
case Value::String_Type:
|
||||||
return value->stringValue();
|
return value->stringValue()->asReturned<String>();
|
||||||
case Value::Object_Type: {
|
case Value::Object_Type: {
|
||||||
Scope scope(ctx);
|
Scope scope(ctx);
|
||||||
ScopedValue prim(scope, __qmljs_to_primitive(value, STRING_HINT));
|
ScopedValue prim(scope, __qmljs_to_primitive(value, STRING_HINT));
|
||||||
return __qmljs_convert_to_string(ctx, prim);
|
return __qmljs_convert_to_string(ctx, prim);
|
||||||
}
|
}
|
||||||
case Value::Integer_Type: {
|
case Value::Integer_Type:
|
||||||
Scope scope(ctx);
|
return __qmljs_string_from_number(ctx, value->int_32);
|
||||||
ScopedValue dbl(scope, __qmljs_string_from_number(ctx, value->int_32));
|
default: // double
|
||||||
return dbl->stringValue();
|
return __qmljs_string_from_number(ctx, value->doubleValue());
|
||||||
}
|
|
||||||
default: { // double
|
|
||||||
Scope scope(ctx);
|
|
||||||
ScopedValue dbl(scope, __qmljs_string_from_number(ctx, value->doubleValue()));
|
|
||||||
return dbl->stringValue();
|
|
||||||
}
|
|
||||||
} // switch
|
} // switch
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -143,8 +143,8 @@ QV4::ReturnedValue __qmljs_init_closure(QV4::ExecutionContext *ctx, int function
|
||||||
|
|
||||||
// strings
|
// strings
|
||||||
Q_QML_EXPORT double __qmljs_string_to_number(const QString &s);
|
Q_QML_EXPORT double __qmljs_string_to_number(const QString &s);
|
||||||
QV4::ReturnedValue __qmljs_string_from_number(QV4::ExecutionContext *ctx, double number);
|
Returned<String> *__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_concat(QV4::ExecutionContext *ctx, QV4::String *first, QV4::String *second);
|
||||||
|
|
||||||
// objects
|
// objects
|
||||||
Q_QML_EXPORT ReturnedValue __qmljs_object_default_value(QV4::Object *object, int typeHint);
|
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);
|
Q_QML_EXPORT QV4::Bool __qmljs_to_boolean(const QV4::ValueRef value);
|
||||||
double __qmljs_to_number(const QV4::ValueRef value);
|
double __qmljs_to_number(const QV4::ValueRef value);
|
||||||
QV4::ReturnedValue __qmljs_to_string(const ValueRef value, QV4::ExecutionContext *ctx);
|
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);
|
void __qmljs_numberToString(QString *result, double num, int radix = 10);
|
||||||
ReturnedValue __qmljs_to_object(QV4::ExecutionContext *ctx, const ValueRef value);
|
ReturnedValue __qmljs_to_object(QV4::ExecutionContext *ctx, const ValueRef value);
|
||||||
Returned<Object> *__qmljs_convert_to_object(QV4::ExecutionContext *ctx, const ValueRef value);
|
Returned<Object> *__qmljs_convert_to_object(QV4::ExecutionContext *ctx, const ValueRef value);
|
||||||
|
|
|
@ -305,7 +305,7 @@ String *Value::toString(ExecutionContext *ctx) const
|
||||||
{
|
{
|
||||||
if (isString())
|
if (isString())
|
||||||
return stringValue();
|
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
|
Object *Value::toObject(ExecutionContext *ctx) const
|
||||||
|
|
Loading…
Reference in New Issue