From 06c286b74274166a47df20dc425f76051fb03d4d Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Fri, 9 Apr 2010 17:18:54 +1000 Subject: Fix crash in QML library imports QTBUG-9705 --- src/declarative/qml/qdeclarativecontext.cpp | 1 + .../qdeclarativeecmascript/data/libraryScriptAssert.js | 6 ++++++ .../qdeclarativeecmascript/data/libraryScriptAssert.qml | 7 +++++++ .../qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp | 12 ++++++++++++ 4 files changed, 26 insertions(+) create mode 100644 tests/auto/declarative/qdeclarativeecmascript/data/libraryScriptAssert.js create mode 100644 tests/auto/declarative/qdeclarativeecmascript/data/libraryScriptAssert.qml diff --git a/src/declarative/qml/qdeclarativecontext.cpp b/src/declarative/qml/qdeclarativecontext.cpp index 55c2f7c..9307bcc 100644 --- a/src/declarative/qml/qdeclarativecontext.cpp +++ b/src/declarative/qml/qdeclarativecontext.cpp @@ -623,6 +623,7 @@ void QDeclarativeContextData::addImportedScript(const QDeclarativeParser::Object if (iter == enginePriv->m_sharedScriptImports.end()) { QScriptContext *scriptContext = QScriptDeclarativeClass::pushCleanContext(scriptEngine); + scriptContext->pushScope(enginePriv->contextClass->newContext(0, 0)); scriptContext->pushScope(enginePriv->globalClass->globalObject()); QScriptValue scope = scriptEngine->newObject(); diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/libraryScriptAssert.js b/tests/auto/declarative/qdeclarativeecmascript/data/libraryScriptAssert.js new file mode 100644 index 0000000..3ffdb33 --- /dev/null +++ b/tests/auto/declarative/qdeclarativeecmascript/data/libraryScriptAssert.js @@ -0,0 +1,6 @@ +.pragma library + +function test(target) +{ + var a = target.a; +} diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/libraryScriptAssert.qml b/tests/auto/declarative/qdeclarativeecmascript/data/libraryScriptAssert.qml new file mode 100644 index 0000000..9e8408f --- /dev/null +++ b/tests/auto/declarative/qdeclarativeecmascript/data/libraryScriptAssert.qml @@ -0,0 +1,7 @@ +import Qt 4.6 +import "libraryScriptAssert.js" as Test + +QtObject { + id: root + Component.onCompleted: Test.test(root); +} diff --git a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp index c6bb276..d886e83 100644 --- a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp +++ b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp @@ -139,6 +139,7 @@ private slots: void regExpBug(); void nullObjectBinding(); void deletedEngine(); + void libraryScriptAssert(); void callQtInvokables(); private: @@ -2179,6 +2180,17 @@ void tst_qdeclarativeecmascript::deletedEngine() delete object; } +// Test the crashing part of QTBUG-9705 +void tst_qdeclarativeecmascript::libraryScriptAssert() +{ + QDeclarativeComponent component(&engine, TEST_FILE("libraryScriptAssert.qml")); + + QObject *object = component.create(); + QVERIFY(object != 0); + + delete object; +} + QTEST_MAIN(tst_qdeclarativeecmascript) #include "tst_qdeclarativeecmascript.moc" -- cgit v0.12