diff options
Diffstat (limited to 'tests/benchmarks/qml/js')
-rw-r--r-- | tests/benchmarks/qml/js/js.pro | 10 | ||||
-rw-r--r-- | tests/benchmarks/qml/js/qjsengine/qjsengine.pro | 7 | ||||
-rw-r--r-- | tests/benchmarks/qml/js/qjsengine/tst_qjsengine.cpp | 600 | ||||
-rw-r--r-- | tests/benchmarks/qml/js/qjsvalue/qjsvalue.pro | 7 | ||||
-rw-r--r-- | tests/benchmarks/qml/js/qjsvalue/tst_qjsvalue.cpp | 979 | ||||
-rw-r--r-- | tests/benchmarks/qml/js/qjsvalueiterator/qjsvalueiterator.pro | 7 | ||||
-rw-r--r-- | tests/benchmarks/qml/js/qjsvalueiterator/tst_qjsvalueiterator.cpp | 309 |
7 files changed, 1919 insertions, 0 deletions
diff --git a/tests/benchmarks/qml/js/js.pro b/tests/benchmarks/qml/js/js.pro new file mode 100644 index 0000000000..b1448d8eb8 --- /dev/null +++ b/tests/benchmarks/qml/js/js.pro @@ -0,0 +1,10 @@ +TEMPLATE = subdirs +SUBDIRS = \ + qjsengine \ + qjsvalue \ + qjsvalueiterator \ + +TRUSTED_BENCHMARKS += \ + qjsvalue \ + qjsengine \ + diff --git a/tests/benchmarks/qml/js/qjsengine/qjsengine.pro b/tests/benchmarks/qml/js/qjsengine/qjsengine.pro new file mode 100644 index 0000000000..f8f2874a63 --- /dev/null +++ b/tests/benchmarks/qml/js/qjsengine/qjsengine.pro @@ -0,0 +1,7 @@ +CONFIG += testcase +TEMPLATE = app +TARGET = tst_bench_qjsengine + +SOURCES += tst_qjsengine.cpp + +QT += qml testlib diff --git a/tests/benchmarks/qml/js/qjsengine/tst_qjsengine.cpp b/tests/benchmarks/qml/js/qjsengine/tst_qjsengine.cpp new file mode 100644 index 0000000000..5713eb2f2e --- /dev/null +++ b/tests/benchmarks/qml/js/qjsengine/tst_qjsengine.cpp @@ -0,0 +1,600 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <qtest.h> +#include <QtQml/qjsvalue.h> +#include <QtQml/qjsengine.h> + + +Q_DECLARE_METATYPE(QJSValue) + +class tst_QJSEngine : public QObject +{ + Q_OBJECT + +public: + tst_QJSEngine(); + virtual ~tst_QJSEngine(); + +public slots: + void init(); + void cleanup(); + +private slots: + void constructor(); +#if 0 // No defaultPrototype for now + void defaultPrototype(); + void setDefaultPrototype(); +#endif + void evaluate_data(); + void evaluate(); +#if 0 // No program + void evaluateProgram_data(); + void evaluateProgram(); +#endif +#if 0 // no connections for now + void connectAndDisconnect(); +#endif + void globalObject(); + void hasUncaughtException(); +#if 0 // no is Evaluating for now + void isEvaluating(); +#endif + void newArray_data(); + void newArray(); + void newDate(); + void newObject(); +#if 0 // No ScriptClass + void newObjectWithScriptClass(); +#endif +#if 0 // no qmetaobject + void newQMetaObject(); +#endif + void newQObject(); +#if 0 // no native functions for now + void newFunction(); +#endif + void newRegExp(); + void newVariant(); + void undefinedValue(); + void collectGarbage(); +#if 0 // No extensions + void availableExtensions(); + void importedExtensions(); +#endif +#if 0 // no context + void currentContext(); + void pushAndPopContext(); +#endif +#if 0 // no stringhandle + void toStringHandle(); +#endif + void castValueToQreal(); +#if 0 // no native functions for now + void nativeCall(); +#endif +#if 0 // no translations + void installTranslatorFunctions(); + void translation_data(); + void translation(); +#endif +#if 0 // no declarative class + void readScopeProperty_data(); + void readScopeProperty(); +#endif +#if 0 // no context + void evaluateInNewContext(); + void evaluateInNewContextWithScope(); +#endif +#if 0 // no pushScope + void evaluateBindingExpression(); +#endif + +private: + void defineStandardTestValues(); + void newEngine() + { + delete m_engine; + m_engine = new QJSEngine; + } + + QJSEngine *m_engine; +}; + +tst_QJSEngine::tst_QJSEngine() + : m_engine(0) +{ +} + +tst_QJSEngine::~tst_QJSEngine() +{ + delete m_engine; +} + +void tst_QJSEngine::init() +{ +} + +void tst_QJSEngine::cleanup() +{ +} + +void tst_QJSEngine::constructor() +{ + QBENCHMARK { + QJSEngine engine; + (void)engine.parent(); + } +} + +#if 0 // No defaultPrototype for now +void tst_QJSEngine::defaultPrototype() +{ + newEngine(); + int type = qMetaTypeId<int>(); + m_engine->setDefaultPrototype(type, m_engine->newObject()); + QBENCHMARK { + m_engine->defaultPrototype(type); + } +} + +void tst_QJSEngine::setDefaultPrototype() +{ + newEngine(); + int type = qMetaTypeId<int>(); + QJSValue proto = m_engine->newObject(); + QBENCHMARK { + m_engine->setDefaultPrototype(type, proto); + } +} + +#endif + +void tst_QJSEngine::evaluate_data() +{ + QTest::addColumn<QString>("code"); + QTest::newRow("empty script") << QString::fromLatin1(""); + QTest::newRow("number literal") << QString::fromLatin1("123"); + QTest::newRow("string literal") << QString::fromLatin1("'ciao'"); + QTest::newRow("regexp literal") << QString::fromLatin1("/foo/gim"); + QTest::newRow("null literal") << QString::fromLatin1("null"); + QTest::newRow("undefined literal") << QString::fromLatin1("undefined"); + QTest::newRow("null literal") << QString::fromLatin1("null"); + QTest::newRow("empty object literal") << QString::fromLatin1("{}"); + QTest::newRow("this") << QString::fromLatin1("this"); + QTest::newRow("object literal with one property") << QString::fromLatin1("{ foo: 123 }"); + QTest::newRow("object literal with two properties") << QString::fromLatin1("{ foo: 123, bar: 456 }"); + QTest::newRow("object literal with many properties") << QString::fromLatin1("{ a: 1, b: 2, c: 3, d: 4, e: 5, f: 6, g: 7, h: 8, i: 9, j: 10 }"); + QTest::newRow("empty array literal") << QString::fromLatin1("[]"); + QTest::newRow("array literal with one element") << QString::fromLatin1("[1]"); + QTest::newRow("array literal with two elements") << QString::fromLatin1("[1,2]"); + QTest::newRow("array literal with many elements") << QString::fromLatin1("[1,2,3,4,5,6,7,8,9,10,9,8,7,6,5,4,3,2,1]"); + QTest::newRow("empty function definition") << QString::fromLatin1("function foo() { }"); + QTest::newRow("function definition") << QString::fromLatin1("function foo() { return 123; }"); + QTest::newRow("for loop with empty body (1000 iterations)") << QString::fromLatin1("for (i = 0; i < 1000; ++i) {}"); + QTest::newRow("for loop with empty body (10000 iterations)") << QString::fromLatin1("for (i = 0; i < 10000; ++i) {}"); + QTest::newRow("for loop with empty body (100000 iterations)") << QString::fromLatin1("for (i = 0; i < 100000; ++i) {}"); + QTest::newRow("for loop with empty body (1000000 iterations)") << QString::fromLatin1("for (i = 0; i < 1000000; ++i) {}"); + QTest::newRow("for loop (1000 iterations)") << QString::fromLatin1("j = 0; for (i = 0; i < 1000; ++i) { j += i; }; j"); + QTest::newRow("for loop (10000 iterations)") << QString::fromLatin1("j = 0; for (i = 0; i < 10000; ++i) { j += i; }; j"); + QTest::newRow("for loop (100000 iterations)") << QString::fromLatin1("j = 0; for (i = 0; i < 100000; ++i) { j += i; }; j"); + QTest::newRow("for loop (1000000 iterations)") << QString::fromLatin1("j = 0; for (i = 0; i < 1000000; ++i) { j += i; }; j"); + QTest::newRow("assignments") << QString::fromLatin1("a = 1; b = 2; c = 3; d = 4"); + QTest::newRow("while loop (1000 iterations)") << QString::fromLatin1("i = 0; while (i < 1000) { ++i; }; i"); + QTest::newRow("while loop (10000 iterations)") << QString::fromLatin1("i = 0; while (i < 10000) { ++i; }; i"); + QTest::newRow("while loop (100000 iterations)") << QString::fromLatin1("i = 0; while (i < 100000) { ++i; }; i"); + QTest::newRow("while loop (1000000 iterations)") << QString::fromLatin1("i = 0; while (i < 1000000) { ++i; }; i"); + QTest::newRow("function expression") << QString::fromLatin1("(function(a, b, c){ return a + b + c; })(1, 2, 3)"); +} + +void tst_QJSEngine::evaluate() +{ + QFETCH(QString, code); + newEngine(); + + QBENCHMARK { + (void)m_engine->evaluate(code); + } +} + +#if 0 +void tst_QJSEngine::connectAndDisconnect() +{ + newEngine(); + QJSValue fun = m_engine->evaluate("(function() { })"); + QBENCHMARK { + qScriptConnect(m_engine, SIGNAL(destroyed()), QJSValue(), fun); + qScriptDisconnect(m_engine, SIGNAL(destroyed()), QJSValue(), fun); + } +} + +void tst_QJSEngine::evaluateProgram_data() +{ + evaluate_data(); +} + +void tst_QJSEngine::evaluateProgram() +{ + QFETCH(QString, code); + QScriptProgram program(code); + newEngine(); + + QBENCHMARK { + (void)m_engine->evaluate(program); + } +} +#endif + +void tst_QJSEngine::globalObject() +{ + newEngine(); + QBENCHMARK { + m_engine->globalObject(); + } +} + +void tst_QJSEngine::hasUncaughtException() +{ + newEngine(); + QBENCHMARK { + m_engine->hasUncaughtException(); + } +} + +#if 0 +void tst_QJSEngine::isEvaluating() +{ + newEngine(); + QBENCHMARK { + m_engine->isEvaluating(); + } +} +#endif + +void tst_QJSEngine::newArray_data() +{ + QTest::addColumn<int>("size"); + QTest::newRow("size=0") << 0; + QTest::newRow("size=10") << 10; + QTest::newRow("size=100") << 0; + QTest::newRow("size=1000") << 0; + QTest::newRow("size=10000") << 0; + QTest::newRow("size=50000") << 0; +} + +void tst_QJSEngine::newArray() +{ + QFETCH(int, size); + newEngine(); + QBENCHMARK { + m_engine->newArray(size); + } +} + +void tst_QJSEngine::newDate() +{ + newEngine(); + QDateTime dt = QDateTime::currentDateTime(); + QBENCHMARK { + m_engine->toScriptValue(dt); + } +} + +void tst_QJSEngine::newObject() +{ + newEngine(); + QBENCHMARK { + (void)m_engine->newObject(); + } +} + +#if 0 +void tst_QJSEngine::newObjectWithScriptClass() +{ + newEngine(); + QScriptClass cls(m_engine); + QBENCHMARK { + m_engine->newObject(&cls); + } +} + +void tst_QJSEngine::newQMetaObject() +{ + newEngine(); + QBENCHMARK { + m_engine->newQMetaObject(&QJSEngine::staticMetaObject); + } +} +#endif + +void tst_QJSEngine::newQObject() +{ + newEngine(); + QBENCHMARK { + (void)m_engine->newQObject(QCoreApplication::instance()); + } +} + +#if 0 +static QJSValue testFunction(QScriptContext *, QJSEngine *) +{ + return 0; +} + +void tst_QJSEngine::newFunction() +{ + newEngine(); + QBENCHMARK { + (void)m_engine->newFunction(testFunction); + } +} +#endif + +void tst_QJSEngine::newRegExp() +{ + newEngine(); + QRegExp re = QRegExp("foo"); + QBENCHMARK { + m_engine->toScriptValue(re); + } +} + +void tst_QJSEngine::newVariant() +{ + newEngine(); + QVariant var(QPoint(10, 20)); + QBENCHMARK { + (void)m_engine->toScriptValue(var); + } +} + +void tst_QJSEngine::undefinedValue() +{ + newEngine(); + QVariant var; + QBENCHMARK { + m_engine->toScriptValue(var); + } +} + +void tst_QJSEngine::collectGarbage() +{ + newEngine(); + QBENCHMARK { + m_engine->collectGarbage(); + } +} + +#if 0 +void tst_QJSEngine::availableExtensions() +{ + newEngine(); + QBENCHMARK { + m_engine->availableExtensions(); + } +} + +void tst_QJSEngine::importedExtensions() +{ + newEngine(); + QBENCHMARK { + m_engine->importedExtensions(); + } +} + +void tst_QJSEngine::currentContext() +{ + newEngine(); + QBENCHMARK { + m_engine->currentContext(); + } +} + +void tst_QJSEngine::pushAndPopContext() +{ + newEngine(); + QBENCHMARK { + (void)m_engine->pushContext(); + m_engine->popContext(); + } +} +#endif + +#if 0 +void tst_QJSEngine::toStringHandle() +{ + newEngine(); + QString str = QString::fromLatin1("foobarbaz"); + QBENCHMARK { + (void)m_engine->toStringHandle(str); + } +} +#endif + +void tst_QJSEngine::castValueToQreal() +{ + QJSValue val(123); + QBENCHMARK { + (void)qjsvalue_cast<qreal>(val); + } +} + +#if 0 +static QJSValue native_function(QScriptContext *, QJSEngine *) +{ + return 42; +} + +void tst_QJSEngine::nativeCall() +{ + newEngine(); + m_engine->globalObject().setProperty("fun", m_engine->newFunction(native_function)); + QBENCHMARK{ + m_engine->evaluate("var w = 0; for (i = 0; i < 100000; ++i) {\n" + " w += fun() + fun(); w -= fun(); fun(); w -= fun(); }"); + } +} + +void tst_QJSEngine::installTranslatorFunctions() +{ + newEngine(); + QBENCHMARK { + m_engine->installTranslatorFunctions(); + } +} + +void tst_QJSEngine::translation_data() +{ + QTest::addColumn<QString>("text"); + QTest::addColumn<QString>("fileName"); + QTest::newRow("no translation") << "\"hello world\"" << ""; + QTest::newRow("qsTr") << "qsTr(\"hello world\")" << ""; + QTest::newRow("qsTranslate") << "qsTranslate(\"\", \"hello world\")" << ""; + QTest::newRow("qsTr:script.js") << "qsTr(\"hello world\")" << "script.js"; +} + +void tst_QJSEngine::translation() +{ + QFETCH(QString, text); + QFETCH(QString, fileName); + newEngine(); + m_engine->installTranslatorFunctions(); + + QBENCHMARK { + (void)m_engine->evaluate(text, fileName); + } +} +#endif + +#if 0 +void tst_QJSEngine::readScopeProperty_data() +{ + QTest::addColumn<bool>("staticScope"); + QTest::addColumn<bool>("nestedScope"); + QTest::newRow("single dynamic scope") << false << false; + QTest::newRow("single static scope") << true << false; + QTest::newRow("double dynamic scope") << false << true; + QTest::newRow("double static scope") << true << true; +} + +void tst_QJSEngine::readScopeProperty() +{ + QFETCH(bool, staticScope); + QFETCH(bool, nestedScope); + + newEngine(); + QScriptContext *ctx = m_engine->pushContext(); + + QJSValue scope; + if (staticScope) + scope = QScriptDeclarativeClass::newStaticScopeObject(m_engine); + else + scope = m_engine->newObject(); + scope.setProperty("foo", 123); + ctx->pushScope(scope); + + if (nestedScope) { + QJSValue scope2; + if (staticScope) + scope2 = QScriptDeclarativeClass::newStaticScopeObject(m_engine); + else + scope2 = m_engine->newObject(); + scope2.setProperty("bar", 456); // ensure a miss in inner scope + ctx->pushScope(scope2); + } + + QJSValue fun = m_engine->evaluate("(function() {\n" + " for (var i = 0; i < 10000; ++i) {\n" + " foo; foo; foo; foo; foo; foo; foo; foo;\n" + " }\n" + "})"); + m_engine->popContext(); + QVERIFY(fun.isFunction()); + QBENCHMARK { + fun.call(); + } +} + +void tst_QJSEngine::evaluateInNewContext() +{ + QJSEngine engine; + QBENCHMARK { + engine.pushContext(); + engine.evaluate("var a = 10"); + engine.popContext(); + } +} + +void tst_QJSEngine::evaluateInNewContextWithScope() +{ + QJSEngine engine; + QJSValue scope = engine.newObject(); + scope.setProperty("foo", 123); + QBENCHMARK { + QScriptContext *ctx = engine.pushContext(); + ctx->pushScope(scope); + engine.evaluate("foo"); + engine.popContext(); + } +} + +// Binding expressions in QML are implemented as anonymous functions +// with custom scopes. +void tst_QJSEngine::evaluateBindingExpression() +{ + QJSEngine engine; + QScriptContext *ctx = engine.pushContext(); + QJSValue scope = engine.newObject(); + scope.setProperty("foo", 123); + ctx->pushScope(scope); + QJSValue fun = engine.evaluate("(function() { return foo; })"); + QVERIFY(fun.isFunction()); + engine.popContext(); + QVERIFY(fun.call().equals(scope.property("foo"))); + QJSValue receiver = engine.globalObject(); + QBENCHMARK { + fun.call(receiver); + } +} +#endif + +QTEST_MAIN(tst_QJSEngine) +#include "tst_qjsengine.moc" diff --git a/tests/benchmarks/qml/js/qjsvalue/qjsvalue.pro b/tests/benchmarks/qml/js/qjsvalue/qjsvalue.pro new file mode 100644 index 0000000000..772aa5da8c --- /dev/null +++ b/tests/benchmarks/qml/js/qjsvalue/qjsvalue.pro @@ -0,0 +1,7 @@ +CONFIG += testcase +TEMPLATE = app +TARGET = tst_bench_qjsvalue + +SOURCES += tst_qjsvalue.cpp + +QT += qml testlib diff --git a/tests/benchmarks/qml/js/qjsvalue/tst_qjsvalue.cpp b/tests/benchmarks/qml/js/qjsvalue/tst_qjsvalue.cpp new file mode 100644 index 0000000000..6c760f37aa --- /dev/null +++ b/tests/benchmarks/qml/js/qjsvalue/tst_qjsvalue.cpp @@ -0,0 +1,979 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <qtest.h> +#include <QtQml/qjsvalue.h> +#include <QtQml/qjsengine.h> + +Q_DECLARE_METATYPE(QJSValue) + +class tst_QJSValue : public QObject +{ + Q_OBJECT + +public: + tst_QJSValue(); + virtual ~tst_QJSValue(); + +public slots: + void init(); + void cleanup(); + +private slots: + void boolConstructor(); + void floatConstructor(); + void numberConstructor(); + void stringConstructor(); + void nullConstructor(); + void undefinedConstructor(); + void boolConstructorWithEngine(); + void floatConstructorWithEngine(); + void intConstructorWithEngine(); + void stringConstructorWithEngine(); + void undefinedConstructorWithEngine(); + void copyConstructor_data(); + void copyConstructor(); + void call_data(); + void call(); + void construct_data(); + void construct(); +#if 0 // no data + void data(); + void setData(); + void data_noData_data(); + void data_noData(); +#endif + void equalsSelf_data(); + void equalsSelf(); +#if 0 // no less then + void lessThanSelf_data(); + void lessThanSelf(); +#endif + void strictlyEqualsSelf_data(); + void strictlyEqualsSelf(); + void isArray_data(); + void isArray(); + void isBool_data(); + void isBool(); + void isDate_data(); + void isDate(); + void isError_data(); + void isError(); + void isCallable_data(); + void isCallable(); + void isNull_data(); + void isNull(); + void isNumber_data(); + void isNumber(); + void isObject_data(); + void isObject(); +#if 0 // no qmetaobject + void isQMetaObject_data(); + void isQMetaObject(); +#endif + void isQObject_data(); + void isQObject(); + void isRegExp_data(); + void isRegExp(); + void isString_data(); + void isString(); + void isUndefined_data(); + void isUndefined(); + void isVariant_data(); + void isVariant(); + void toBool_data(); + void toBool(); + void toDateTime_data(); + void toDateTime(); + void toInt_data(); + void toInt(); + void toNumber_data(); + void toNumber(); + void toRegExp_data(); + void toRegExp(); + void toString_data(); + void toString(); + void toUInt_data(); + void toUInt(); +#if 0 // no qmetaobject + void toQMetaObject_data(); + void toQMetaObject(); +#endif + void toQObject_data(); + void toQObject(); + void toVariant_data(); + void toVariant(); + void property_data(); + void property(); +#if 0 // no string handle + void propertyById_data(); + void propertyById(); +#endif + void propertyByIndex(); + void setProperty_data(); + void setProperty(); +#if 0 // no string handle + void setPropertyById_data(); + void setPropertyById(); +#endif + void setPropertyByIndex(); +#if 0 // no propertyFlags for now + void propertyFlags_data(); + void propertyFlags(); + void propertyFlagsById_data(); + void propertyFlagsById(); +#endif + void prototype_data(); + void prototype(); + void setPrototype(); +#if 0 // no script class + void scriptClass_data(); + void scriptClass(); + void setScriptClass(); +#endif +#if 0 // no string handle + void readMetaProperty(); + void writeMetaProperty(); +#endif + +private: + void defineStandardTestValues(); + void newEngine() + { + delete m_engine; + m_engine = new QJSEngine; + } + + QJSEngine *m_engine; +}; + +tst_QJSValue::tst_QJSValue() + : m_engine(0) +{ +} + +tst_QJSValue::~tst_QJSValue() +{ + delete m_engine; +} + +void tst_QJSValue::init() +{ +} + +void tst_QJSValue::cleanup() +{ +} + +void tst_QJSValue::boolConstructor() +{ + QBENCHMARK { + QJSValue val(true); + } +} + +void tst_QJSValue::floatConstructor() +{ + QBENCHMARK { + QJSValue val(123.0); + } +} + +void tst_QJSValue::numberConstructor() +{ + QBENCHMARK { + (void)QJSValue(123); + } +} + +void tst_QJSValue::stringConstructor() +{ + QString str = QString::fromLatin1("ciao"); + QBENCHMARK { + (void)QJSValue(str); + } +} + +void tst_QJSValue::nullConstructor() +{ + QBENCHMARK { + QJSValue val(QJSValue::NullValue); + } +} + +void tst_QJSValue::undefinedConstructor() +{ + QBENCHMARK { + QJSValue val(QJSValue::UndefinedValue); + } +} + +void tst_QJSValue::boolConstructorWithEngine() +{ + newEngine(); + QBENCHMARK { + m_engine->toScriptValue(true); + } +} + +void tst_QJSValue::floatConstructorWithEngine() +{ + newEngine(); + QBENCHMARK { + m_engine->toScriptValue(123.0); + } +} + +void tst_QJSValue::intConstructorWithEngine() +{ + newEngine(); + QBENCHMARK { + m_engine->toScriptValue(123); + } +} + +void tst_QJSValue::stringConstructorWithEngine() +{ + newEngine(); + QString str = QString::fromLatin1("ciao"); + QBENCHMARK { + m_engine->toScriptValue(str); + } +} + +void tst_QJSValue::undefinedConstructorWithEngine() +{ + newEngine(); + QVariant var; + QBENCHMARK { + m_engine->toScriptValue(var); + } +} + +void tst_QJSValue::copyConstructor_data() +{ + defineStandardTestValues(); +} + +void tst_QJSValue::copyConstructor() +{ + QFETCH(QJSValue, val); + QBENCHMARK { + QJSValue copy(val); + } +} + +void tst_QJSValue::call_data() +{ + newEngine(); + QTest::addColumn<QString>("code"); + QTest::newRow("empty function") << QString::fromLatin1("(function(){})"); + QTest::newRow("function returning number") << QString::fromLatin1("(function(){ return 123; })"); + QTest::newRow("closure") << QString::fromLatin1("(function(a, b){ return function() { return a + b; }; })(1, 2)"); +} + +void tst_QJSValue::call() +{ + QFETCH(QString, code); + QJSValue fun = m_engine->evaluate(code); + QVERIFY(fun.isCallable()); + QBENCHMARK { + (void)fun.call(); + } +} + +void tst_QJSValue::construct_data() +{ + newEngine(); + QTest::addColumn<QString>("code"); + QTest::newRow("empty function") << QString::fromLatin1("(function(){})"); + QTest::newRow("simple constructor") << QString::fromLatin1("(function(){ this.x = 10; this.y = 20; })"); +} + +void tst_QJSValue::construct() +{ + QFETCH(QString, code); + QJSValue fun = m_engine->evaluate(code); + QVERIFY(fun.isCallable()); + QBENCHMARK { + (void)fun.callAsConstructor(); + } +} + +#if 0 +void tst_QJSValue::data() +{ + newEngine(); + QJSValue obj = m_engine->newObject(); + obj.setData(QJSValue(m_engine, 123)); + QBENCHMARK { + obj.data(); + } +} + +void tst_QJSValue::setData() +{ + newEngine(); + QJSValue obj = m_engine->newObject(); + QJSValue val(m_engine, 123); + QBENCHMARK { + obj.setData(val); + } +} + +void tst_QJSValue::data_noData_data() +{ + defineStandardTestValues(); +} + +void tst_QJSValue::data_noData() +{ + QFETCH(QJSValue, val); + QVERIFY(!val.data().isValid()); + QBENCHMARK { + val.data(); + } +} +#endif + +void tst_QJSValue::equalsSelf_data() +{ + defineStandardTestValues(); +} + +void tst_QJSValue::equalsSelf() +{ + QFETCH(QJSValue, val); + QBENCHMARK { + val.equals(val); + } +} + +#if 0 +void tst_QJSValue::lessThanSelf_data() +{ + defineStandardTestValues(); +} + +void tst_QJSValue::lessThanSelf() +{ + QFETCH(QJSValue, val); + QBENCHMARK { + val.lessThan(val); + } +} +#endif + +void tst_QJSValue::strictlyEqualsSelf_data() +{ + defineStandardTestValues(); +} + +void tst_QJSValue::strictlyEqualsSelf() +{ + QFETCH(QJSValue, val); + QBENCHMARK { + val.strictlyEquals(val); + } +} + +void tst_QJSValue::isArray_data() +{ + defineStandardTestValues(); +} + +void tst_QJSValue::isArray() +{ + QFETCH(QJSValue, val); + QBENCHMARK { + val.isArray(); + } +} + +void tst_QJSValue::isBool_data() +{ + defineStandardTestValues(); +} + +void tst_QJSValue::isBool() +{ + QFETCH(QJSValue, val); + QBENCHMARK { + val.isBool(); + } +} + +void tst_QJSValue::isDate_data() +{ + defineStandardTestValues(); +} + +void tst_QJSValue::isDate() +{ + QFETCH(QJSValue, val); + QBENCHMARK { + val.isDate(); + } +} + +void tst_QJSValue::isError_data() +{ + defineStandardTestValues(); +} + +void tst_QJSValue::isError() +{ + QFETCH(QJSValue, val); + QBENCHMARK { + val.isError(); + } +} + +void tst_QJSValue::isCallable_data() +{ + defineStandardTestValues(); +} + +void tst_QJSValue::isCallable() +{ + QFETCH(QJSValue, val); + QBENCHMARK { + val.isCallable(); + } +} + +void tst_QJSValue::isNull_data() +{ + defineStandardTestValues(); +} + +void tst_QJSValue::isNull() +{ + QFETCH(QJSValue, val); + QBENCHMARK { + val.isNull(); + } +} + +void tst_QJSValue::isNumber_data() +{ + defineStandardTestValues(); +} + +void tst_QJSValue::isNumber() +{ + QFETCH(QJSValue, val); + QBENCHMARK { + val.isNumber(); + } +} + +void tst_QJSValue::isObject_data() +{ + defineStandardTestValues(); +} + +void tst_QJSValue::isObject() +{ + QFETCH(QJSValue, val); + QBENCHMARK { + val.isObject(); + } +} + +#if 0 +void tst_QJSValue::isQMetaObject_data() +{ + defineStandardTestValues(); +} + +void tst_QJSValue::isQMetaObject() +{ + QFETCH(QJSValue, val); + QBENCHMARK { + val.isQMetaObject(); + } +} +#endif + +void tst_QJSValue::isQObject_data() +{ + defineStandardTestValues(); +} + +void tst_QJSValue::isQObject() +{ + QFETCH(QJSValue, val); + QBENCHMARK { + val.isQObject(); + } +} + +void tst_QJSValue::isRegExp_data() +{ + defineStandardTestValues(); +} + +void tst_QJSValue::isRegExp() +{ + QFETCH(QJSValue, val); + QBENCHMARK { + val.isRegExp(); + } +} + +void tst_QJSValue::isString_data() +{ + defineStandardTestValues(); +} + +void tst_QJSValue::isString() +{ + QFETCH(QJSValue, val); + QBENCHMARK { + val.isString(); + } +} + +void tst_QJSValue::isUndefined_data() +{ + defineStandardTestValues(); +} + +void tst_QJSValue::isUndefined() +{ + QFETCH(QJSValue, val); + QBENCHMARK { + val.isUndefined(); + } +} + +void tst_QJSValue::isVariant_data() +{ + defineStandardTestValues(); +} + +void tst_QJSValue::isVariant() +{ + QFETCH(QJSValue, val); + QBENCHMARK { + val.isVariant(); + } +} + +void tst_QJSValue::toBool_data() +{ + defineStandardTestValues(); +} + +void tst_QJSValue::toBool() +{ + QFETCH(QJSValue, val); + QBENCHMARK { + val.toBool(); + } +} + +void tst_QJSValue::toDateTime_data() +{ + defineStandardTestValues(); +} + +void tst_QJSValue::toDateTime() +{ + QFETCH(QJSValue, val); + QBENCHMARK { + val.toDateTime(); + } +} + +void tst_QJSValue::toInt_data() +{ + defineStandardTestValues(); +} + +void tst_QJSValue::toInt() +{ + QFETCH(QJSValue, val); + QBENCHMARK { + val.toInt(); + } +} + +void tst_QJSValue::toNumber_data() +{ + defineStandardTestValues(); +} + +void tst_QJSValue::toNumber() +{ + QFETCH(QJSValue, val); + QBENCHMARK { + val.toNumber(); + } +} + +void tst_QJSValue::toRegExp_data() +{ + defineStandardTestValues(); +} + +void tst_QJSValue::toRegExp() +{ + QFETCH(QJSValue, val); + QBENCHMARK { + qjsvalue_cast<QRegExp>(val); + } +} + +void tst_QJSValue::toString_data() +{ + defineStandardTestValues(); +} + +void tst_QJSValue::toString() +{ + QFETCH(QJSValue, val); + QBENCHMARK { + (void)val.toString(); + } +} + +#if 0 +void tst_QJSValue::toQMetaObject_data() +{ + defineStandardTestValues(); +} + +void tst_QJSValue::toQMetaObject() +{ + QFETCH(QJSValue, val); + QBENCHMARK { + val.toQMetaObject(); + } +} +#endif + +void tst_QJSValue::toQObject_data() +{ + defineStandardTestValues(); +} + +void tst_QJSValue::toQObject() +{ + QFETCH(QJSValue, val); + QBENCHMARK { + (void)val.toQObject(); + } +} + +void tst_QJSValue::toUInt_data() +{ + defineStandardTestValues(); +} + +void tst_QJSValue::toUInt() +{ + QFETCH(QJSValue, val); + QBENCHMARK { + val.toUInt(); + } +} + +void tst_QJSValue::toVariant_data() +{ + defineStandardTestValues(); +} + +void tst_QJSValue::toVariant() +{ + QFETCH(QJSValue, val); + QBENCHMARK { + val.toVariant(); + } +} +void tst_QJSValue::property_data() +{ + QTest::addColumn<QString>("propertyName"); + QTest::addColumn<bool>("create"); + QTest::newRow("foo") << QString::fromLatin1("foo") << true; + QTest::newRow("hasOwnProperty") << QString::fromLatin1("hasOwnProperty") << false; // From Object.prototype. + QTest::newRow("noSuchProperty") << QString::fromLatin1("noSuchProperty") << false; +} + +void tst_QJSValue::property() +{ + QFETCH(QString, propertyName); + QFETCH(bool, create); + newEngine(); + QJSValue obj = m_engine->newObject(); + if (create) + obj.setProperty(propertyName, 123); + QBENCHMARK { + (void)obj.property(propertyName); + } +} + +#if 0 +void tst_QJSValue::propertyById_data() +{ + property_data(); +} + +void tst_QJSValue::propertyById() +{ + QFETCH(QString, propertyName); + QFETCH(bool, create); + newEngine(); + QJSValue obj = m_engine->newObject(); + QJSString id = m_engine->toStringHandle(propertyName); + if (create) + obj.setProperty(id, 123); + QBENCHMARK { + obj.property(id); + } +} +#endif + +void tst_QJSValue::propertyByIndex() +{ + newEngine(); + QJSValue obj = m_engine->newObject(); + obj.setProperty(123, 456); + QBENCHMARK { + obj.property(123); + } +} + +void tst_QJSValue::setProperty_data() +{ + newEngine(); + QTest::addColumn<QString>("propertyName"); + QTest::addColumn<QJSValue>("val"); + QTest::newRow("foo") << QString::fromLatin1("foo") << QJSValue(123); + QTest::newRow("bar") << QString::fromLatin1("bar") << m_engine->toScriptValue(123); + QTest::newRow("baz") << QString::fromLatin1("baz") << QJSValue(); + QTest::newRow("toString") << QString::fromLatin1("toString") << m_engine->toScriptValue(true); +} + +void tst_QJSValue::setProperty() +{ + QFETCH(QString, propertyName); + QFETCH(QJSValue, val); + QJSValue obj = m_engine->newObject(); + QBENCHMARK { + obj.setProperty(propertyName, val); + } +} + +#if 0 +void tst_QJSValue::setPropertyById_data() +{ + setProperty_data(); +} + +void tst_QJSValue::setPropertyById() +{ + QFETCH(QString, propertyName); + QFETCH(QJSValue, val); + QJSValue obj = m_engine->newObject(); + QJSString id = m_engine->toStringHandle(propertyName); + QBENCHMARK { + obj.setProperty(id, val); + } +} +#endif + +void tst_QJSValue::setPropertyByIndex() +{ + newEngine(); + QJSValue obj = m_engine->newObject(); + QJSValue val(456); + QBENCHMARK { + obj.setProperty(123, 456); + } +} + +#if 0 +void tst_QJSValue::propertyFlags_data() +{ + property_data(); +} + +void tst_QJSValue::propertyFlags() +{ + QFETCH(QString, propertyName); + QFETCH(bool, create); + newEngine(); + QJSValue obj = m_engine->newObject(); + if (create) + obj.setProperty(propertyName, 123, QJSValue::SkipInEnumeration | QJSValue::ReadOnly); + QBENCHMARK { + (void)obj.propertyFlags(propertyName); + } +} + +void tst_QJSValue::propertyFlagsById_data() +{ + propertyFlags_data(); +} + +void tst_QJSValue::propertyFlagsById() +{ + QFETCH(QString, propertyName); + QFETCH(bool, create); + newEngine(); + QJSValue obj = m_engine->newObject(); + QJSString id = m_engine->toStringHandle(propertyName); + if (create) + obj.setProperty(id, 123, QJSValue::SkipInEnumeration | QJSValue::ReadOnly); + QBENCHMARK { + obj.propertyFlags(id); + } +} +#endif + +void tst_QJSValue::prototype_data() +{ + defineStandardTestValues(); +} + +void tst_QJSValue::prototype() +{ + QFETCH(QJSValue, val); + QBENCHMARK { + val.prototype(); + } +} + +void tst_QJSValue::setPrototype() +{ + newEngine(); + QJSValue obj = m_engine->newObject(); + QJSValue proto = m_engine->newObject(); + QBENCHMARK { + obj.setPrototype(proto); + } +} + +#if 0 +void tst_QJSValue::scriptClass_data() +{ + defineStandardTestValues(); +} + +void tst_QJSValue::scriptClass() +{ + QFETCH(QJSValue, val); + QBENCHMARK { + val.scriptClass(); + } +} + +void tst_QJSValue::setScriptClass() +{ + newEngine(); + QJSValue obj = m_engine->newObject(); + QJSClass cls(m_engine); + QBENCHMARK { + obj.setScriptClass(&cls); + } +} + +void tst_QJSValue::readMetaProperty() +{ + newEngine(); + QJSValue object = m_engine->newQObject(QCoreApplication::instance()); + QJSString propertyName = m_engine->toStringHandle("objectName"); + QBENCHMARK { + for (int i = 0; i < 10000; ++i) + object.property(propertyName); + } +} + +void tst_QJSValue::writeMetaProperty() +{ + newEngine(); + QJSValue object = m_engine->newQObject(QCoreApplication::instance()); + QJSString propertyName = m_engine->toStringHandle("objectName"); + QJSValue value(m_engine, "foo"); + QBENCHMARK { + for (int i = 0; i < 10000; ++i) + object.setProperty(propertyName, value); + } +} +#endif + +void tst_QJSValue::defineStandardTestValues() +{ + newEngine(); + QTest::addColumn<QJSValue>("val"); + QTest::newRow("bool") << m_engine->evaluate("true"); + QTest::newRow("number") << m_engine->evaluate("123"); + QTest::newRow("string") << m_engine->evaluate("'ciao'"); + QTest::newRow("null") << m_engine->evaluate("null"); + QTest::newRow("undefined") << m_engine->evaluate("undefined"); + QTest::newRow("object") << m_engine->evaluate("({foo:123})"); + QTest::newRow("array") << m_engine->evaluate("[10,20,30]"); + QTest::newRow("function") << m_engine->evaluate("(function foo(a, b, c) { return a + b + c; })"); + QTest::newRow("date") << m_engine->evaluate("new Date"); + QTest::newRow("regexp") << m_engine->evaluate("new RegExp('foo')"); + QTest::newRow("error") << m_engine->evaluate("new Error"); + + QTest::newRow("qobject") << m_engine->newQObject(this); +#if 0 // no qmetaobject + QTest::newRow("qmetaobject") << m_engine->newQMetaObject(&QJSEngine::staticMetaObject); +#endif + QTest::newRow("variant") << m_engine->toScriptValue(QPoint(10, 20)); +#if 0 // no classess + QTest::newRow("qscriptclassobject") << m_engine->newObject(new QJSClass(m_engine)); +#endif + + QTest::newRow("invalid") << QJSValue(); + QTest::newRow("bool-no-engine") << QJSValue(true); + QTest::newRow("number-no-engine") << QJSValue(123.0); + QTest::newRow("string-no-engine") << QJSValue(QString::fromLatin1("hello")); + QTest::newRow("null-no-engine") << QJSValue(QJSValue::NullValue); + QTest::newRow("undefined-no-engine") << QJSValue(QJSValue::UndefinedValue); +} + +QTEST_MAIN(tst_QJSValue) +#include "tst_qjsvalue.moc" diff --git a/tests/benchmarks/qml/js/qjsvalueiterator/qjsvalueiterator.pro b/tests/benchmarks/qml/js/qjsvalueiterator/qjsvalueiterator.pro new file mode 100644 index 0000000000..7601789ca9 --- /dev/null +++ b/tests/benchmarks/qml/js/qjsvalueiterator/qjsvalueiterator.pro @@ -0,0 +1,7 @@ +CONFIG += testcase +TEMPLATE = app +TARGET = tst_bench_qjsvalueiterator + +SOURCES += tst_qjsvalueiterator.cpp + +QT = core qml testlib diff --git a/tests/benchmarks/qml/js/qjsvalueiterator/tst_qjsvalueiterator.cpp b/tests/benchmarks/qml/js/qjsvalueiterator/tst_qjsvalueiterator.cpp new file mode 100644 index 0000000000..51c6cffd99 --- /dev/null +++ b/tests/benchmarks/qml/js/qjsvalueiterator/tst_qjsvalueiterator.cpp @@ -0,0 +1,309 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <qtest.h> +#include <QtQml/qjsengine.h> +#include <QtQml/qjsvalue.h> +#include <QtQml/qjsvalueiterator.h> + +class tst_QJSValueIterator : public QObject +{ + Q_OBJECT + +public: + tst_QJSValueIterator(); + virtual ~tst_QJSValueIterator(); + + void dataHelper(); + +private slots: + void init(); + void cleanup(); + + void hasNextAndNext(); + + void constructAndNext_data(); + void constructAndNext(); + + void name_data(); + void name(); +#if 0 // No string handle + void scriptName_data(); + void scriptName(); +#endif + + void value_data(); + void value(); +#if 0 // no setValue + void setValue_data(); + void setValue(); +#endif +#if 0 // no flags + void flags(); +#endif + +#if 0 // no array index + void iterateArrayAndConvertNameToIndex(); +#endif +#if 0 // no setValue + void iterateArrayAndDoubleElements(); +#endif +#if 0 // no remove + void iterateArrayAndRemoveAllElements(); +#endif +}; + +tst_QJSValueIterator::tst_QJSValueIterator() +{ +} + +tst_QJSValueIterator::~tst_QJSValueIterator() +{ +} + +void tst_QJSValueIterator::init() +{ +} + +void tst_QJSValueIterator::cleanup() +{ +} + +void tst_QJSValueIterator::dataHelper() +{ + QTest::addColumn<QString>("code"); + QTest::newRow("{ foo: 123 }") << QString::fromLatin1("({ foo: 123 })"); + QTest::newRow("Math") << QString::fromLatin1("Math"); + QTest::newRow("Array.prototype") << QString::fromLatin1("Array.prototype"); + QTest::newRow("Global Object") << QString::fromLatin1("this"); + QTest::newRow("['foo']") << QString::fromLatin1("['foo']"); + QTest::newRow("array with 1000 elements") + << QString::fromLatin1("(function() {" + " var a = new Array;" + " for (i = 0; i < 1000; ++i)" + " a[i] = i;" + " return a;" + "})()"); +} + +void tst_QJSValueIterator::hasNextAndNext() +{ + QJSEngine engine; + QJSValue object = engine.newObject(); + for (int i = 0; i < 2000; ++i) + object.setProperty(i, i); + QBENCHMARK { + for (int i = 0; i < 1000; ++i) { + QJSValueIterator it(object); + while (it.hasNext()) + it.next(); + } + } +} + +void tst_QJSValueIterator::constructAndNext_data() +{ + dataHelper(); +} + +void tst_QJSValueIterator::constructAndNext() +{ + QFETCH(QString, code); + QJSEngine engine; + QJSValue object = engine.evaluate(code); + Q_ASSERT(object.isObject()); + + QBENCHMARK { + for (int i = 0; i < 100; ++i) { + QJSValueIterator it(object); + it.next(); + } + } +} + +void tst_QJSValueIterator::name_data() +{ + dataHelper(); +} + +void tst_QJSValueIterator::name() +{ + QFETCH(QString, code); + QJSEngine engine; + QJSValue object = engine.evaluate(code); + Q_ASSERT(object.isObject()); + + QJSValueIterator it(object); + it.next(); + QBENCHMARK { + for (int i = 0; i < 200000; ++i) + it.name(); + } +} + +#if 0 +void tst_QJSValueIterator::scriptName_data() +{ + dataHelper(); +} + +void tst_QJSValueIterator::scriptName() +{ + QFETCH(QString, code); + QJSEngine engine; + QJSValue object = engine.evaluate(code); + Q_ASSERT(object.isObject()); + + QJSValueIterator it(object); + it.next(); + QBENCHMARK { + for (int i = 0; i < 50000; ++i) + it.scriptName(); + } +} +#endif + +void tst_QJSValueIterator::value_data() +{ + dataHelper(); +} + +void tst_QJSValueIterator::value() +{ + QFETCH(QString, code); + QJSEngine engine; + QJSValue object = engine.evaluate(code); + Q_ASSERT(object.isObject()); + + QJSValueIterator it(object); + it.next(); + QBENCHMARK { + for (int i = 0; i < 50000; ++i) + it.value(); + } +} + +#if 0 +void tst_QJSValueIterator::setValue_data() +{ + dataHelper(); +} + +void tst_QJSValueIterator::setValue() +{ + QFETCH(QString, code); + QJSEngine engine; + QJSValue object = engine.evaluate(code); + Q_ASSERT(object.isObject()); + + QJSValueIterator it(object); + it.next(); + QJSValue newValue(&engine, 456); + QBENCHMARK { + for (int i = 0; i < 50000; ++i) + it.setValue(newValue); + } +} + +void tst_QJSValueIterator::flags() +{ + QJSEngine engine; + QJSValue object = engine.newObject(); + QJSValue::PropertyFlags flags = flags; + object.setProperty("foo", 123, QJSValue::SkipInEnumeration | QJSValue::ReadOnly | QJSValue::Undeletable); + QJSValueIterator it(object); + it.next(); + QBENCHMARK { + for (int i = 0; i < 50000; ++i) + it.flags(); + } +} +#endif + +#if 0 +void tst_QJSValueIterator::iterateArrayAndConvertNameToIndex() +{ + QJSEngine engine; + QJSValue array = engine.newArray(); + for (int i = 0; i < 20000; ++i) + array.setProperty(i, i); + QBENCHMARK { + QJSValueIterator it(array); + while (it.hasNext()) { + it.next(); + it.scriptName().toArrayIndex(); + } + } +} + +void tst_QJSValueIterator::iterateArrayAndDoubleElements() +{ + QJSEngine engine; + QJSValue array = engine.newArray(); + for (int i = 0; i < 20000; ++i) + array.setProperty(i, i); + QBENCHMARK { + QJSValueIterator it(array); + while (it.hasNext()) { + it.next(); + it.setValue(QJSValue(&engine, it.value().toNumber() * 2)); + } + } +} + +void tst_QJSValueIterator::iterateArrayAndRemoveAllElements() +{ + QJSEngine engine; + QJSValue array = engine.newArray(); + for (int i = 0; i < 20000; ++i) + array.setProperty(i, i); + QBENCHMARK { + QJSValueIterator it(array); + while (it.hasNext()) { + it.next(); + it.remove(); + } + } +} +#endif + +QTEST_MAIN(tst_QJSValueIterator) +#include "tst_qjsvalueiterator.moc" |