summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Varga <pvarga@inf.u-szeged.hu>2012-11-26 16:47:43 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-01-11 10:24:01 +0100
commitba4f4d65b93e28ea0272cc1427c95dd2c9b6ed33 (patch)
treef4f4b6f13e60bee7484df6d1b42cc4c542a03fc4
parent78927b3ca01d5f3f1a2d3ac6e992046326b144ab (diff)
downloadqtjsbackend-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>
-rw-r--r--tests/auto/v8/tst_v8.cpp6
-rw-r--r--tests/auto/v8/v8main.cpp1
-rw-r--r--tests/auto/v8/v8test.cpp63
-rw-r--r--tests/auto/v8/v8test.h1
4 files changed, 71 insertions, 0 deletions
diff --git a/tests/auto/v8/tst_v8.cpp b/tests/auto/v8/tst_v8.cpp
index 235158e..f13e8f5 100644
--- a/tests/auto/v8/tst_v8.cpp
+++ b/tests/auto/v8/tst_v8.cpp
@@ -68,6 +68,7 @@ private slots:
void fallbackpropertyhandler_nonempty();
void completehash();
void stringhashcomparison();
+ void qmlmodevariables();
};
void tst_v8::eval()
@@ -140,6 +141,11 @@ void tst_v8::stringhashcomparison()
QVERIFY(v8test_stringhashcomparison());
}
+void tst_v8::qmlmodevariables()
+{
+ QVERIFY(v8test_qmlmodevariables());
+}
+
int main(int argc, char *argv[])
{
V8::SetFlagsFromCommandLine(&argc, argv, true);
diff --git a/tests/auto/v8/v8main.cpp b/tests/auto/v8/v8main.cpp
index 309a900..fe75bd9 100644
--- a/tests/auto/v8/v8main.cpp
+++ b/tests/auto/v8/v8main.cpp
@@ -74,6 +74,7 @@ int main(int argc, char *argv[])
RUN_TEST(fallbackpropertyhandler_in_prototype);
RUN_TEST(fallbackpropertyhandler_nonempty);
RUN_TEST(completehash);
+ RUN_TEST(qmlmodevariables);
return exit_status;
}
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();
+}
diff --git a/tests/auto/v8/v8test.h b/tests/auto/v8/v8test.h
index 4132fd4..900d25f 100644
--- a/tests/auto/v8/v8test.h
+++ b/tests/auto/v8/v8test.h
@@ -62,6 +62,7 @@ bool v8test_fallbackpropertyhandler_in_prototype();
bool v8test_fallbackpropertyhandler_nonempty();
bool v8test_completehash();
bool v8test_stringhashcomparison();
+bool v8test_qmlmodevariables();
#endif // V8TEST_H