Commit 89c57d28 authored by Michael Brasser's avatar Michael Brasser Committed by Qt by Nokia

Support null -> QObject and QObject -> bool conversions in v4.

Change-Id: I66602bf52986a388f9b6fe2bcd4630b862138906
Reviewed-by: default avatarRoberto Raggi <roberto.raggi@nokia.com>
parent 47e08179
......@@ -1160,6 +1160,25 @@ void QV4Bindings::run(int instrIndex, quint32 &executedBlocks,
}
QML_V4_END_INSTR(ConvertColorToString, unaryop)
QML_V4_BEGIN_INSTR(ConvertObjectToBool, unaryop)
{
const Register &src = registers[instr->unaryop.src];
Register &output = registers[instr->unaryop.output];
// ### NaN
if (src.isUndefined())
output.setUndefined();
else
output.setbool(src.getQObject() != 0);
}
QML_V4_END_INSTR(ConvertObjectToBool, unaryop)
QML_V4_BEGIN_INSTR(ConvertNullToObject, unaryop)
{
Register &output = registers[instr->unaryop.output];
output.setQObject(0);
}
QML_V4_END_INSTR(ConvertNullToObject, unaryop)
QML_V4_BEGIN_INSTR(ResolveUrl, unaryop)
{
const Register &src = registers[instr->unaryop.src];
......
......@@ -958,6 +958,7 @@ void QV4CompilerPrivate::visitMove(IR::Move *s)
case IR::StringType: opcode = V4Instr::ConvertStringToBool; break;
case IR::UrlType: opcode = V4Instr::ConvertUrlToBool; break;
case IR::ColorType: opcode = V4Instr::ConvertColorToBool; break;
case IR::ObjectType: opcode = V4Instr::ConvertObjectToBool; break;
default: break;
} // switch
} else if (targetTy == IR::IntType) {
......@@ -1010,6 +1011,11 @@ void QV4CompilerPrivate::visitMove(IR::Move *s)
case IR::StringType: opcode = V4Instr::ConvertStringToColor; break;
default: break;
} // switch
} else if (targetTy == IR::ObjectType) {
switch (sourceTy) {
case IR::NullType: opcode = V4Instr::ConvertNullToObject; break;
default: break;
} // switch
}
if (opcode != V4Instr::Noop) {
V4Instr conv;
......
......@@ -189,6 +189,12 @@ void Bytecode::dump(const V4Instr *i, int address) const
case V4Instr::ConvertColorToString:
INSTR_DUMP << "\t" << "ConvertColorToString" << "\t" << "Input_Reg(" << i->unaryop.src << ") -> Output_Reg(" << i->unaryop.output << ")";
break;
case V4Instr::ConvertObjectToBool:
INSTR_DUMP << "\t" << "ConvertObjectToBool" << "\t" << "Input_Reg(" << i->unaryop.src << ") -> Output_Reg(" << i->unaryop.output << ")";
break;
case V4Instr::ConvertNullToObject:
INSTR_DUMP << "\t" << "ConvertNullToObject" << "\t" << "Input_Reg(" << i->unaryop.src << ") -> Output_Reg(" << i->unaryop.output << ")";
break;
case V4Instr::ResolveUrl:
INSTR_DUMP << "\t" << "ResolveUrl" << "\t\t" << "Input_Reg(" << i->unaryop.src << ") -> Output_Reg(" << i->unaryop.output << ")";
break;
......
......@@ -98,6 +98,8 @@ QT_BEGIN_NAMESPACE
F(ConvertUrlToString, unaryop) \
F(ConvertColorToBool, unaryop) \
F(ConvertColorToString, unaryop) \
F(ConvertObjectToBool, unaryop) \
F(ConvertNullToObject, unaryop) \
F(ResolveUrl, unaryop) \
F(MathSinReal, unaryop) \
F(MathCosReal, unaryop) \
......
import QtQuick 2.0
QtObject {
property QtObject prop1: null
property QtObject prop2: QtObject {}
property bool test1: prop1 ? true : false
property bool test2: prop2 ? true : false
property bool test3: prop1 == false
property bool test4: prop1 === false
property bool test5: prop2 == false
property bool test6: prop2 === false
}
......@@ -133,6 +133,7 @@ void tst_v4::qtscript_data()
QTest::newRow("double bool jump") << "doubleBoolJump.qml";
QTest::newRow("unary minus") << "unaryMinus.qml";
QTest::newRow("null qobject") << "nullQObject.qml";
QTest::newRow("qobject -> bool") << "objectToBool.qml";
}
void tst_v4::unnecessaryReeval()
......
Markdown is supported
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