ArrayObject::ArrayObject(ExecutionEngine *engine, const QStringList &list)
: Object(engine)
{
+ init(engine);
+
// Converts a QStringList to JS.
// The result is a new Array object with length equal to the length
// of the QStringList, and the elements being the QStringList's
return false;
if (x.isString())
return x.stringValue()->isEqualTo(y.stringValue());
- if (x.isObject())
- return x.objectValue()->isEqualTo(y.objectValue());
return false;
}
inline bool isObject() const { return tag == Object_Type; }
#endif
inline bool isConvertibleToInt() const { return (tag & ConvertibleToInt) == ConvertibleToInt; }
+ inline bool isInt32() const {
+ if (tag == _Integer_Type)
+ return true;
+ if (isDouble() && (int)dbl == dbl)
+ return true;
+ return false;
+ }
Bool booleanValue() const {
return int_32;
#include "qv4functionobject_p.h"
#include "qv4objectproto_p.h"
#include <private/qqmlvaluetypewrapper_p.h>
+#include <private/qv8engine_p.h>
QT_BEGIN_NAMESPACE
QVariant VariantObject::toVariant(const QV4::Value &v)
{
- VariantObject *o = v.as<QV4::VariantObject>();
- return o ? o->data : QVariant();
+ if (Object *o = v.asObject())
+ return o->engine()->v8Engine->variantFromJS(v);
+
+ if (v.isString())
+ return QVariant(v.stringValue()->toQString());
+ if (v.isBoolean())
+ return QVariant(v.booleanValue());
+ if (v.isNumber()) {
+ if (v.isInt32())
+ return QVariant(v.toInt32());
+ return QVariant(v.asDouble());
+ }
+ if (v.isNull())
+ return QVariant(QMetaType::VoidStar, 0);
+ assert (v.isUndefined() || v.isEmpty());
+ return QVariant();
}
bool VariantObject::isScarce() const
if (!o)
return Value::undefinedValue();
QString result = o->data.toString();
- if (result.isEmpty())
+ if (result.isEmpty() && !o->data.canConvert(QVariant::String))
result = QString::fromLatin1("QVariant(%0)").arg(QString::fromLatin1(o->data.typeName()));
return Value::fromString(ctx->engine->newString(result));
}
a->arrayReserve(lst.size());
for (int i = 0; i < lst.size(); i++)
a->arrayData[i].value = variantToJS(lst.at(i));
+ a->arrayDataLen = lst.size();
a->setArrayLengthUnchecked(lst.size());
return QV4::Value::fromObject(a);
}
quint32 length = a->arrayLength();
for (quint32 i = 0; i < length; ++i) {
- QV4::Value v = a->getIndexed(m_v4Engine->current, i);
+ QV4::Value v = a->getIndexed(i);
result.append(variantFromJS(v, visitedObjects));
}
{
QJSValue var1 = eng.toScriptValue(QVariant(QPoint(1, 2)));
QJSValue var2 = eng.toScriptValue(QVariant(QPoint(1, 2)));
- QEXPECT_FAIL("", "FIXME: QVariant comparison does not work with v8", Continue);
QVERIFY(var1.equals(var2));
}
{
QJSValue var2 = eng.toScriptValue(QVariant(QPoint(3, 4)));
QVERIFY(!var1.equals(var2));
}
-
- QJSEngine otherEngine;
- QTest::ignoreMessage(QtWarningMsg, "QJSValue::equals: "
- "cannot compare to a value created in "
- "a different engine");
- QCOMPARE(date1.equals(otherEngine.toScriptValue(123)), false);
}
void tst_QJSValue::strictlyEquals()
QJSValue var2 = eng.toScriptValue(QVariant(QPoint(3, 4)));
QVERIFY(!var1.strictlyEquals(var2));
}
-
- QJSEngine otherEngine;
- QTest::ignoreMessage(QtWarningMsg, "QJSValue::strictlyEquals: "
- "cannot compare to a value created in "
- "a different engine");
- QCOMPARE(date1.strictlyEquals(otherEngine.toScriptValue(123)), false);
}
Q_DECLARE_METATYPE(int*)