\table
\header \li Input Type \li Result
\row \li Undefined \li An invalid QVariant.
- \row \li Null \li An invalid QVariant.
+ \row \li Null \li A QVariant containing a null pointer (QMetaType::VoidStar).
\row \li Boolean \li A QVariant containing the value of the boolean.
\row \li Number \li A QVariant containing the value of the number.
\row \li String \li A QVariant containing the value of the string.
case CNumber:
return QVariant(u.m_number);
case CNull:
- return QVariant();
+ return QVariant(QMetaType::VoidStar, 0);
case CUndefined:
return QVariant();
case JSValue:
}
// Converts a JS value to a QVariant.
-// Null, Undefined -> QVariant() (invalid)
+// Undefined -> QVariant() (invalid)
+// Null -> QVariant((void*)0)
// Boolean -> QVariant(bool)
// Number -> QVariant(double)
// String -> QVariant(QString)
QVariant QV8Engine::variantFromJS(v8::Handle<v8::Value> value)
{
Q_ASSERT(!value.IsEmpty());
- if (value->IsNull() || value->IsUndefined())
+ if (value->IsUndefined())
return QVariant();
+ if (value->IsNull())
+ return QVariant(QMetaType::VoidStar, 0);
if (value->IsBoolean())
return value->ToBoolean()->Value();
if (value->IsInt32())
QCOMPARE(eng.fromScriptValue<QChar>(code), c);
QCOMPARE(eng.fromScriptValue<QChar>(eng.toScriptValue(c)), c);
}
+
+ QVERIFY(eng.toScriptValue(static_cast<void *>(0)).isNull());
}
#if 0 // FIXME: No API for custom types
}
QCOMPARE(qjsvalue_cast<QVariant>(QJSValue(123)), QVariant(123));
+
+ QVERIFY(eng.toScriptValue(QVariant(QMetaType::VoidStar, 0)).isNull());
}
#if 0 // FIXME: No support for custom types
QCOMPARE(qjsvalue_cast<QVariant>(undefined), QVariant());
QJSValue null = eng.evaluate("null");
- QCOMPARE(null.toVariant(), QVariant());
- QCOMPARE(qjsvalue_cast<QVariant>(null), QVariant());
+ QCOMPARE(null.toVariant(), QVariant(QMetaType::VoidStar, 0));
+ QCOMPARE(qjsvalue_cast<QVariant>(null), QVariant(QMetaType::VoidStar, 0));
{
QJSValue number = eng.toScriptValue(123.0);
QJSValue str = QJSValue(QString("ciao"));
QCOMPARE(str.toVariant(), QVariant(QString("ciao")));
QCOMPARE(qjsvalue_cast<QVariant>(str), QVariant(QString("ciao")));
+
+ QJSValue undef = QJSValue(QJSValue::UndefinedValue);
+ QCOMPARE(undef.toVariant(), QVariant());
+ QCOMPARE(qjsvalue_cast<QVariant>(undef), QVariant());
+
+ QJSValue nil = QJSValue(QJSValue::NullValue);
+ QCOMPARE(nil.toVariant(), QVariant(QMetaType::VoidStar, 0));
+ QCOMPARE(qjsvalue_cast<QVariant>(nil), QVariant(QMetaType::VoidStar, 0));
}
#if 0 // FIXME: No automatic sequence conversion