summaryrefslogtreecommitdiff
path: root/tests/auto/v8/v8test.cpp
diff options
context:
space:
mode:
authorSergio Ahumada <sergio.ahumada@digia.com>2013-03-19 09:25:14 +0100
committerSergio Ahumada <sergio.ahumada@digia.com>2013-03-19 09:56:31 +0100
commit6313e1fe4c27755adde87e62db1c2f9fac534ae4 (patch)
treec57bb29f65e02fbfcc07895a8cc2903fff9300ba /tests/auto/v8/v8test.cpp
parentb5a49a260d03249c386f1b63c249089383dd81fa (diff)
parentcac65e7a222b848a735a974b0aeb43209b0cfa18 (diff)
downloadqtjsbackend-6313e1fe4c27755adde87e62db1c2f9fac534ae4.tar.gz
Merge branch 'dev' into stable
This starts Qt 5.1 release cycle Change-Id: I892bbc73c276842894a720f761ce31ad1b015672
Diffstat (limited to 'tests/auto/v8/v8test.cpp')
-rw-r--r--tests/auto/v8/v8test.cpp63
1 files changed, 63 insertions, 0 deletions
diff --git a/tests/auto/v8/v8test.cpp b/tests/auto/v8/v8test.cpp
index 77a7146..6621846 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();
+}