From ffccebed9af217cc5bf2f3e4eba00df754eb7ac9 Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Tue, 18 May 2010 16:09:53 +1000 Subject: Make Qt.include() work for js files that have '.pragma library' --- src/declarative/qml/qdeclarativeinclude.cpp | 3 +++ .../qdeclarativeecmascript/data/include_pragma.qml | 11 +++++++++++ .../qdeclarativeecmascript/data/include_pragma_inner.js | 5 +++++ .../qdeclarativeecmascript/data/include_pragma_outer.js | 6 ++++++ .../qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp | 11 +++++++++++ 5 files changed, 36 insertions(+) create mode 100644 tests/auto/declarative/qdeclarativeecmascript/data/include_pragma.qml create mode 100644 tests/auto/declarative/qdeclarativeecmascript/data/include_pragma_inner.js create mode 100644 tests/auto/declarative/qdeclarativeecmascript/data/include_pragma_outer.js diff --git a/src/declarative/qml/qdeclarativeinclude.cpp b/src/declarative/qml/qdeclarativeinclude.cpp index 619264a..e37b68b 100644 --- a/src/declarative/qml/qdeclarativeinclude.cpp +++ b/src/declarative/qml/qdeclarativeinclude.cpp @@ -140,6 +140,7 @@ void QDeclarativeInclude::finished() scriptContext->pushScope(m_scope[1]); scriptContext->setActivationObject(m_scope[1]); + QDeclarativeScriptParser::extractPragmas(code); m_scriptEngine->evaluate(code, urlString, 1); @@ -230,6 +231,7 @@ QScriptValue QDeclarativeInclude::include(QScriptContext *ctxt, QScriptEngine *e QScriptValue scope = QScriptDeclarativeClass::scopeChainValue(ctxt, -5); scriptContext->pushScope(scope); scriptContext->setActivationObject(scope); + QDeclarativeScriptParser::extractPragmas(code); engine->evaluate(code, urlString, 1); @@ -291,6 +293,7 @@ QScriptValue QDeclarativeInclude::worker_include(QScriptContext *ctxt, QScriptEn QScriptValue scope = QScriptDeclarativeClass::scopeChainValue(ctxt, -4); scriptContext->pushScope(scope); scriptContext->setActivationObject(scope); + QDeclarativeScriptParser::extractPragmas(code); engine->evaluate(code, urlString, 1); diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/include_pragma.qml b/tests/auto/declarative/qdeclarativeecmascript/data/include_pragma.qml new file mode 100644 index 0000000..67b8cfd --- /dev/null +++ b/tests/auto/declarative/qdeclarativeecmascript/data/include_pragma.qml @@ -0,0 +1,11 @@ +import Qt 4.7 +import "include_pragma_outer.js" as Script + +Item { + property int test1 + + Component.onCompleted: { + test1 = Script.callFunction() + } +} + diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/include_pragma_inner.js b/tests/auto/declarative/qdeclarativeecmascript/data/include_pragma_inner.js new file mode 100644 index 0000000..a0380a2 --- /dev/null +++ b/tests/auto/declarative/qdeclarativeecmascript/data/include_pragma_inner.js @@ -0,0 +1,5 @@ +.pragma library + +function getValue() { + return 100; +} diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/include_pragma_outer.js b/tests/auto/declarative/qdeclarativeecmascript/data/include_pragma_outer.js new file mode 100644 index 0000000..d87bafc --- /dev/null +++ b/tests/auto/declarative/qdeclarativeecmascript/data/include_pragma_outer.js @@ -0,0 +1,6 @@ +Qt.include("include_pragma_inner.js") + +function callFunction() { + return getValue(); +} + diff --git a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp index 0710e15..9a88237 100644 --- a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp +++ b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp @@ -2424,6 +2424,17 @@ void tst_qdeclarativeecmascript::include() delete o; } + // Including file with ".pragma library" + { + QDeclarativeComponent component(&engine, TEST_FILE("include_pragma.qml")); + qDebug() << "errors:" << component.errorsString(); + QObject *o = component.create(); + QVERIFY(o != 0); + QCOMPARE(o->property("test1").toInt(), 100); + + delete o; + } + // Remote - success { TestHTTPServer server(8111); -- cgit v0.12