QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(engine);
QV8Engine *v8engine = ep->v8engine();
- // XXX Handle errors during the script compile!
+ // If compilation throws an error, a surrounding v8::TryCatch will record it.
v8::Local<v8::Script> program = v8engine->qmlModeCompile(m_programSource, url.toString(), 1);
+ if (program.IsEmpty())
+ return;
+
m_program = qPersistentNew<v8::Script>(program);
addToEngine(engine);
v8::HandleScope handle_scope;
v8::Context::Scope scope(v8engine->context());
- if (!script->isInitialized())
+ v8::TryCatch try_catch;
+ if (!script->isInitialized())
script->initialize(parentCtxt->engine);
v8::Local<v8::Object> qmlglobal = v8engine->qmlScope(ctxt, 0);
- v8::TryCatch try_catch;
- script->m_program->Run(qmlglobal);
+ if (!script->m_program.IsEmpty()) {
+ script->m_program->Run(qmlglobal);
+ } else {
+ // Compilation failed.
+ Q_ASSERT(try_catch.HasCaught());
+ }
v8::Persistent<v8::Object> rv;
void invokableObjectRet();
void qtbug_20344();
void qtbug_22679();
+ void qtbug_22843_data();
+ void qtbug_22843();
void revisionErrors();
void revision();
delete o;
}
+void tst_qdeclarativeecmascript::qtbug_22843_data()
+{
+ QTest::addColumn<bool>("library");
+
+ QTest::newRow("without .pragma library") << false;
+ QTest::newRow("with .pragma library") << true;
+}
+
+void tst_qdeclarativeecmascript::qtbug_22843()
+{
+ QFETCH(bool, library);
+
+ QString fileName("qtbug_22843");
+ if (library)
+ fileName += QLatin1String(".library");
+ fileName += QLatin1String(".qml");
+
+ QDeclarativeComponent component(&engine, TEST_FILE(fileName));
+ QString url = component.url().toString();
+ QString warning1 = url.left(url.length()-3) + QLatin1String("js:4: SyntaxError: Unexpected token )");
+ QString warning2 = url + QLatin1String(":5: TypeError: Object [object Object] has no method 'func'");
+
+ qRegisterMetaType<QList<QDeclarativeError> >("QList<QDeclarativeError>");
+ QSignalSpy warningsSpy(&engine, SIGNAL(warnings(QList<QDeclarativeError>)));
+ for (int x = 0; x < 3; ++x) {
+ warningsSpy.clear();
+ // For libraries, only the first import attempt should produce a
+ // SyntaxError warning; subsequent component creation should not
+ // attempt to reload the script.
+ bool expectSyntaxError = !library || (x == 0);
+ if (expectSyntaxError)
+ QTest::ignoreMessage(QtWarningMsg, qPrintable(warning1));
+ QTest::ignoreMessage(QtWarningMsg, qPrintable(warning2));
+ QObject *object = component.create();
+ QVERIFY(object != 0);
+ QCOMPARE(warningsSpy.count(), 1 + (expectSyntaxError?1:0));
+ delete object;
+ }
+}
+
QTEST_MAIN(tst_qdeclarativeecmascript)
#include "tst_qdeclarativeecmascript.moc"
invalidFiles << "tests/auto/declarative/qdeclarativelanguage/data/nonexistantProperty.5.qml";
invalidFiles << "tests/auto/declarative/qdeclarativefolderlistmodel/data/dummy.qml";
invalidFiles << "tests/auto/declarative/qdeclarativeecmascript/data/blank.js";
+ invalidFiles << "tests/auto/declarative/qdeclarativeecmascript/data/qtbug_22843.js";
+ invalidFiles << "tests/auto/declarative/qdeclarativeecmascript/data/qtbug_22843.library.js";
invalidFiles << "tests/auto/declarative/qdeclarativeworkerscript/data/script_error_onLoad.js";
invalidFiles << "tests/auto/declarative/qdeclarativelanguage/data/test.js";
invalidFiles << "tests/auto/declarative/qdeclarativelanguage/data/test2.js";