Skip to content

Commit

Permalink
Include correct line number when throwing an exception from a slot
Browse files Browse the repository at this point in the history
Task-number: QTBUG-20344
Change-Id: I25be1520b55ce13d4e1c75e06effa1dee8530a7a
Reviewed-by: Aaron Kennedy <aaron.kennedy@nokia.com>
  • Loading branch information
Aaron Kennedy authored and Qt by Nokia committed Nov 8, 2011
1 parent ad320d8 commit 46e54ea
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/declarative/qml/v8/qv8qobjectwrapper.cpp
Expand Up @@ -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 };
Expand Down
@@ -0,0 +1,6 @@
import QtQuick 2.0
import Qt.test 1.0

MyQmlObject {
Component.onCompleted: v8function()
}
6 changes: 6 additions & 0 deletions tests/auto/declarative/qdeclarativeecmascript/testtypes.cpp
Expand Up @@ -101,6 +101,12 @@ class QWidgetDeclarativeUI : public QObject
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)
Expand Down
2 changes: 2 additions & 0 deletions tests/auto/declarative/qdeclarativeecmascript/testtypes.h
Expand Up @@ -59,6 +59,7 @@

#include <private/qv8gccallback_p.h>
#include <private/qdeclarativeengine_p.h>
#include <private/qv8engine_p.h>

class MyQmlAttachedObject : public QObject
{
Expand Down Expand Up @@ -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;
Expand Down
Expand Up @@ -222,7 +222,7 @@ private slots:
void callQtInvokables();
void invokableObjectArg();
void invokableObjectRet();

void qtbug_20344();
void revisionErrors();
void revision();

Expand Down Expand Up @@ -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()
{
{
Expand Down

0 comments on commit 46e54ea

Please sign in to comment.