Include correct line number when throwing an exception from a slot
authorAaron Kennedy <aaron.kennedy@nokia.com>
Mon, 7 Nov 2011 18:38:44 +0000 (18:38 +0000)
committerQt by Nokia <qt-info@nokia.com>
Tue, 8 Nov 2011 11:18:11 +0000 (12:18 +0100)
Task-number: QTBUG-20344
Change-Id: I25be1520b55ce13d4e1c75e06effa1dee8530a7a
Reviewed-by: Aaron Kennedy <aaron.kennedy@nokia.com>
src/declarative/qml/v8/qv8qobjectwrapper.cpp
tests/auto/declarative/qdeclarativeecmascript/data/qtbug_20344.qml [new file with mode: 0644]
tests/auto/declarative/qdeclarativeecmascript/testtypes.cpp
tests/auto/declarative/qdeclarativeecmascript/testtypes.h
tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp

index eea455d..d93e1b8 100644 (file)
@@ -298,7 +298,8 @@ void QV8QObjectWrapper::init(QV8Engine *engine)
     }
     {
     v8::ScriptOrigin origin(m_hiddenObject); // Hack to allow us to identify these functions
-    v8::Local<v8::Script> script = v8::Script::New(v8::String::New(CREATE_FUNCTION), &origin);
+    v8::Local<v8::Script> script = v8::Script::New(v8::String::New(CREATE_FUNCTION), &origin, 0,
+                                                   v8::Handle<v8::String>(), v8::Script::NativeMode);
     v8::Local<v8::Function> fn = v8::Local<v8::Function>::Cast(script->Run());
     v8::Handle<v8::Value> invokeFn = v8::FunctionTemplate::New(Invoke)->GetFunction();
     v8::Handle<v8::Value> args[] = { invokeFn };
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/qtbug_20344.qml b/tests/auto/declarative/qdeclarativeecmascript/data/qtbug_20344.qml
new file mode 100644 (file)
index 0000000..f490848
--- /dev/null
@@ -0,0 +1,6 @@
+import QtQuick 2.0
+import Qt.test 1.0
+
+MyQmlObject {
+    Component.onCompleted: v8function()
+}
index 9213b61..721c719 100644 (file)
@@ -101,6 +101,12 @@ public:
     void setWidth(int) { }
 };
 
+void MyQmlObject::v8function(QDeclarativeV8Function *args)
+{
+    const char *error = "Exception thrown from within QObject slot";
+    v8::ThrowException(v8::Exception::Error(v8::String::New(error)));
+}
+
 static QJSValue script_api(QDeclarativeEngine *engine, QJSEngine *scriptEngine)
 {
     Q_UNUSED(engine)
index 9fbbd50..12563d6 100644 (file)
@@ -59,6 +59,7 @@
 
 #include <private/qv8gccallback_p.h>
 #include <private/qdeclarativeengine_p.h>
+#include <private/qv8engine_p.h>
 
 class MyQmlAttachedObject : public QObject
 {
@@ -184,6 +185,7 @@ public slots:
     void setString(const QString &s) { m_string = s; }
     void myinvokable(MyQmlObject *o) { myinvokableObject = o; }
     void variantMethod(const QVariant &v) { m_variant = v; }
+    void v8function(QDeclarativeV8Function*);
 
 private:
     friend class tst_qdeclarativeecmascript;
index 57e4fe1..0a44c3e 100644 (file)
@@ -222,7 +222,7 @@ private slots:
     void callQtInvokables();
     void invokableObjectArg();
     void invokableObjectRet();
-
+    void qtbug_20344();
     void revisionErrors();
     void revision();
 
@@ -4910,6 +4910,19 @@ void tst_qdeclarativeecmascript::aliasToCompositeElement()
     delete object;
 }
 
+void tst_qdeclarativeecmascript::qtbug_20344()
+{
+    QDeclarativeComponent component(&engine, TEST_FILE("qtbug_20344.qml"));
+
+    QString warning = component.url().toString() + ":5: Error: Exception thrown from within QObject slot";
+    QTest::ignoreMessage(QtWarningMsg, qPrintable(warning));
+
+    QObject *object = component.create();
+    QVERIFY(object != 0);
+
+    delete object;
+}
+
 void tst_qdeclarativeecmascript::revisionErrors()
 {
     {