diff options
author | Peter Varga <pvarga@inf.u-szeged.hu> | 2012-11-26 16:47:43 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-01-11 10:24:01 +0100 |
commit | ba4f4d65b93e28ea0272cc1427c95dd2c9b6ed33 (patch) | |
tree | f4f4b6f13e60bee7484df6d1b42cc4c542a03fc4 /tests/auto/v8/v8test.cpp | |
parent | 78927b3ca01d5f3f1a2d3ac6e992046326b144ab (diff) | |
download | qtjsbackend-ba4f4d65b93e28ea0272cc1427c95dd2c9b6ed33.tar.gz |
Add testcase for variable declaration when QML compilation mode is enabled
Change-Id: I04596a40a5953cb8c93a28f10e07c3ba33dc4793
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'tests/auto/v8/v8test.cpp')
-rw-r--r-- | tests/auto/v8/v8test.cpp | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/tests/auto/v8/v8test.cpp b/tests/auto/v8/v8test.cpp index 2f434bb..4a1153a 100644 --- a/tests/auto/v8/v8test.cpp +++ b/tests/auto/v8/v8test.cpp @@ -1147,3 +1147,66 @@ cleanup: ENDTEST(); } #endif + +// Test whether the variables are declared in the appropriate scope +// when script is compiled in QML compilation mode. +bool v8test_qmlmodevariables() +{ + BEGINTEST(); + + HandleScope handle_scope; + Persistent<Context> context = Context::New(); + Context::Scope context_scope(context); + + Local<Object> global = context->Global(); + Local<Object> qmlglobal = Object::New(); + + qmlglobal->Set(String::New("eval"), Integer::New(1922)); + qmlglobal->Set(String::New("b"), Integer::New(28)); + global->Set(String::New("x"), Integer::New(32)); + global->Set(String::New("y"), Integer::New(40)); + + // Different declarations regarding to the binding kind. + Local<String> source = String::New( + "function f() { return 28; }" // function is bound at parse-time + "var a = 42;" // bound variable declared in qmlglobal scope + "eval(\"b\");" // unbound variable declared in qmlglobal scope + "const c = 28;" // constant is bound at parse-time + "var x = 2;" // bound variable declared in global scope + "eval(\"y\");" // unbound variable declared in global scope + ); + Local<Script> script = Script::Compile(source, NULL, NULL, Handle<String>(), Script::QmlMode); + + TryCatch tc; + script->Run(qmlglobal); + VERIFY(!tc.HasCaught()); + + // Check redeclaration of a global JS function. + VERIFY(global->HasOwnProperty(String::New("eval"))); + VERIFY(qmlglobal->HasOwnProperty(String::New("eval"))); + + // The following variables should be declared in the qmlglobal scope. + VERIFY(!global->HasOwnProperty(String::New("f"))); + VERIFY(qmlglobal->HasOwnProperty(String::New("f"))); + + VERIFY(!global->HasOwnProperty(String::New("a"))); + VERIFY(qmlglobal->HasOwnProperty(String::New("a"))); + + VERIFY(!global->HasOwnProperty(String::New("b"))); + VERIFY(qmlglobal->HasOwnProperty(String::New("b"))); + + VERIFY(!global->HasOwnProperty(String::New("c"))); + VERIFY(qmlglobal->HasOwnProperty(String::New("c"))); + + // The following variables should be declared in the global scope. + VERIFY(global->HasOwnProperty(String::New("x"))); + VERIFY(!qmlglobal->HasOwnProperty(String::New("x"))); + + VERIFY(global->HasOwnProperty(String::New("y"))); + VERIFY(!qmlglobal->HasOwnProperty(String::New("y"))); + +cleanup: + context.Dispose(); + + ENDTEST(); +} |