diff options
Diffstat (limited to 'tests/benchmarks/script/qscriptengine/tst_qscriptengine.cpp')
-rw-r--r-- | tests/benchmarks/script/qscriptengine/tst_qscriptengine.cpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/benchmarks/script/qscriptengine/tst_qscriptengine.cpp b/tests/benchmarks/script/qscriptengine/tst_qscriptengine.cpp index 15ba6b9..355caea 100644 --- a/tests/benchmarks/script/qscriptengine/tst_qscriptengine.cpp +++ b/tests/benchmarks/script/qscriptengine/tst_qscriptengine.cpp @@ -101,6 +101,9 @@ private slots: void translation(); void readScopeProperty_data(); void readScopeProperty(); + void evaluateInNewContext(); + void evaluateInNewContextWithScope(); + void evaluateBindingExpression(); private: void defineStandardTestValues(); @@ -576,5 +579,47 @@ void tst_QScriptEngine::readScopeProperty() } } +void tst_QScriptEngine::evaluateInNewContext() +{ + QScriptEngine engine; + QBENCHMARK { + engine.pushContext(); + engine.evaluate("var a = 10"); + engine.popContext(); + } +} + +void tst_QScriptEngine::evaluateInNewContextWithScope() +{ + QScriptEngine engine; + QScriptValue 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_QScriptEngine::evaluateBindingExpression() +{ + QScriptEngine engine; + QScriptContext *ctx = engine.pushContext(); + QScriptValue scope = engine.newObject(); + scope.setProperty("foo", 123); + ctx->pushScope(scope); + QScriptValue fun = engine.evaluate("(function() { return foo; })"); + QVERIFY(fun.isFunction()); + engine.popContext(); + QVERIFY(fun.call().equals(scope.property("foo"))); + QScriptValue receiver = engine.globalObject(); + QBENCHMARK { + fun.call(receiver); + } +} + QTEST_MAIN(tst_QScriptEngine) #include "tst_qscriptengine.moc" |