Commit aa92c84e authored by Roberto Raggi's avatar Roberto Raggi
Browse files

Group the members of ConvertToString and ConvertToNumber.

parent 204aeb70
......@@ -1060,6 +1060,45 @@ const Value *ConvertToNumber::switchResult(const Value *value)
return previousResult;
}
void ConvertToNumber::visit(const NullValue *)
{
_result = _engine->numberValue();
}
void ConvertToNumber::visit(const UndefinedValue *)
{
_result = _engine->numberValue();
}
void ConvertToNumber::visit(const NumberValue *value)
{
_result = value;
}
void ConvertToNumber::visit(const BooleanValue *)
{
_result = _engine->numberValue();
}
void ConvertToNumber::visit(const StringValue *)
{
_result = _engine->numberValue();
}
void ConvertToNumber::visit(const ObjectValue *object)
{
if (const FunctionValue *valueOfMember = value_cast<const FunctionValue *>(object->lookup("valueOf"))) {
_result = value_cast<const NumberValue *>(valueOfMember->call(object)); // ### invoke convert-to-number?
}
}
void ConvertToNumber::visit(const FunctionValue *object)
{
if (const FunctionValue *valueOfMember = value_cast<const FunctionValue *>(object->lookup("valueOf"))) {
_result = value_cast<const NumberValue *>(valueOfMember->call(object)); // ### invoke convert-to-number?
}
}
ConvertToString::ConvertToString(Engine *engine)
: _engine(engine), _result(0)
{
......@@ -1082,6 +1121,45 @@ const Value *ConvertToString::switchResult(const Value *value)
return previousResult;
}
void ConvertToString::visit(const NullValue *)
{
_result = _engine->stringValue();
}
void ConvertToString::visit(const UndefinedValue *)
{
_result = _engine->stringValue();
}
void ConvertToString::visit(const NumberValue *)
{
_result = _engine->stringValue();
}
void ConvertToString::visit(const BooleanValue *)
{
_result = _engine->stringValue();
}
void ConvertToString::visit(const StringValue *value)
{
_result = value;
}
void ConvertToString::visit(const ObjectValue *object)
{
if (const FunctionValue *toStringMember = value_cast<const FunctionValue *>(object->lookup("toString"))) {
_result = value_cast<const StringValue *>(toStringMember->call(object)); // ### invoke convert-to-string?
}
}
void ConvertToString::visit(const FunctionValue *object)
{
if (const FunctionValue *toStringMember = value_cast<const FunctionValue *>(object->lookup("toString"))) {
_result = value_cast<const StringValue *>(toStringMember->call(object)); // ### invoke convert-to-string?
}
}
ConvertToObject::ConvertToObject(Engine *engine)
: _engine(engine), _result(0)
{
......@@ -1740,86 +1818,3 @@ ObjectValue *Engine::newQmlObject(const QString &name)
#endif
}
////////////////////////////////////////////////////////////////////////////////
// convert to number
////////////////////////////////////////////////////////////////////////////////
void ConvertToNumber::visit(const NullValue *)
{
_result = _engine->numberValue();
}
void ConvertToNumber::visit(const UndefinedValue *)
{
_result = _engine->numberValue();
}
void ConvertToNumber::visit(const NumberValue *value)
{
_result = value;
}
void ConvertToNumber::visit(const BooleanValue *)
{
_result = _engine->numberValue();
}
void ConvertToNumber::visit(const StringValue *)
{
_result = _engine->numberValue();
}
void ConvertToNumber::visit(const ObjectValue *object)
{
if (const FunctionValue *valueOfMember = value_cast<const FunctionValue *>(object->lookup("valueOf"))) {
_result = value_cast<const NumberValue *>(valueOfMember->call(object)); // ### invoke convert-to-number?
}
}
void ConvertToNumber::visit(const FunctionValue *object)
{
if (const FunctionValue *valueOfMember = value_cast<const FunctionValue *>(object->lookup("valueOf"))) {
_result = value_cast<const NumberValue *>(valueOfMember->call(object)); // ### invoke convert-to-number?
}
}
////////////////////////////////////////////////////////////////////////////////
// convert to string
////////////////////////////////////////////////////////////////////////////////
void ConvertToString::visit(const NullValue *)
{
_result = _engine->stringValue();
}
void ConvertToString::visit(const UndefinedValue *)
{
_result = _engine->stringValue();
}
void ConvertToString::visit(const NumberValue *)
{
_result = _engine->stringValue();
}
void ConvertToString::visit(const BooleanValue *)
{
_result = _engine->stringValue();
}
void ConvertToString::visit(const StringValue *value)
{
_result = value;
}
void ConvertToString::visit(const ObjectValue *object)
{
if (const FunctionValue *toStringMember = value_cast<const FunctionValue *>(object->lookup("toString"))) {
_result = value_cast<const StringValue *>(toStringMember->call(object)); // ### invoke convert-to-string?
}
}
void ConvertToString::visit(const FunctionValue *object)
{
if (const FunctionValue *toStringMember = value_cast<const FunctionValue *>(object->lookup("toString"))) {
_result = value_cast<const StringValue *>(toStringMember->call(object)); // ### invoke convert-to-string?
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment