72 void toStringHandle(); |
74 void toStringHandle(); |
73 void castValueToQreal(); |
75 void castValueToQreal(); |
74 void nativeCall(); |
76 void nativeCall(); |
75 void translation_data(); |
77 void translation_data(); |
76 void translation(); |
78 void translation(); |
|
79 void readScopeProperty_data(); |
|
80 void readScopeProperty(); |
77 }; |
81 }; |
78 |
82 |
79 tst_QScriptEngine::tst_QScriptEngine() |
83 tst_QScriptEngine::tst_QScriptEngine() |
80 { |
84 { |
81 } |
85 } |
286 QBENCHMARK { |
290 QBENCHMARK { |
287 (void)engine.evaluate(text, fileName); |
291 (void)engine.evaluate(text, fileName); |
288 } |
292 } |
289 } |
293 } |
290 |
294 |
|
295 void tst_QScriptEngine::readScopeProperty_data() |
|
296 { |
|
297 QTest::addColumn<bool>("staticScope"); |
|
298 QTest::addColumn<bool>("nestedScope"); |
|
299 QTest::newRow("single dynamic scope") << false << false; |
|
300 QTest::newRow("single static scope") << true << false; |
|
301 QTest::newRow("double dynamic scope") << false << true; |
|
302 QTest::newRow("double static scope") << true << true; |
|
303 } |
|
304 |
|
305 void tst_QScriptEngine::readScopeProperty() |
|
306 { |
|
307 QFETCH(bool, staticScope); |
|
308 QFETCH(bool, nestedScope); |
|
309 |
|
310 QScriptEngine engine; |
|
311 QScriptContext *ctx = engine.pushContext(); |
|
312 |
|
313 QScriptValue scope; |
|
314 if (staticScope) |
|
315 scope = QScriptDeclarativeClass::newStaticScopeObject(&engine); |
|
316 else |
|
317 scope = engine.newObject(); |
|
318 scope.setProperty("foo", 123); |
|
319 ctx->pushScope(scope); |
|
320 |
|
321 if (nestedScope) { |
|
322 QScriptValue scope2; |
|
323 if (staticScope) |
|
324 scope2 = QScriptDeclarativeClass::newStaticScopeObject(&engine); |
|
325 else |
|
326 scope2 = engine.newObject(); |
|
327 scope2.setProperty("bar", 456); // ensure a miss in inner scope |
|
328 ctx->pushScope(scope2); |
|
329 } |
|
330 |
|
331 QScriptValue fun = engine.evaluate("(function() {\n" |
|
332 " for (var i = 0; i < 10000; ++i) {\n" |
|
333 " foo; foo; foo; foo; foo; foo; foo; foo;\n" |
|
334 " }\n" |
|
335 "})"); |
|
336 engine.popContext(); |
|
337 QVERIFY(fun.isFunction()); |
|
338 QBENCHMARK { |
|
339 fun.call(); |
|
340 } |
|
341 } |
|
342 |
291 QTEST_MAIN(tst_QScriptEngine) |
343 QTEST_MAIN(tst_QScriptEngine) |
292 #include "tst_qscriptengine.moc" |
344 #include "tst_qscriptengine.moc" |