aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml/qqmlerror.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/qml/qml/qqmlerror.cpp')
-rw-r--r--src/qml/qml/qqmlerror.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/qml/qml/qqmlerror.cpp b/src/qml/qml/qqmlerror.cpp
index 0c8e46bd8d..3a4179717a 100644
--- a/src/qml/qml/qqmlerror.cpp
+++ b/src/qml/qml/qqmlerror.cpp
@@ -46,6 +46,8 @@
#include <QtCore/qfile.h>
#include <QtCore/qstringlist.h>
+#include <private/qv4errorobject_p.h>
+
QT_BEGIN_NAMESPACE
/*!
@@ -136,6 +138,28 @@ QQmlError::~QQmlError()
delete d; d = 0;
}
+QQmlError QQmlError::catchJavaScriptException(QV4::ExecutionContext *context)
+{
+ QV4::StackTrace trace;
+ QV4::Scope scope(context);
+ QV4::ScopedValue exception(scope, context->catchException(&trace));
+ QQmlError error;
+ if (!trace.isEmpty()) {
+ QV4::StackFrame frame = trace.first();
+ error.setUrl(QUrl(frame.source));
+ error.setLine(frame.line);
+ error.setColumn(frame.column);
+ }
+ QV4::Scoped<QV4::ErrorObject> errorObj(scope, exception);
+ if (!!errorObj && errorObj->asSyntaxError()) {
+ QV4::ScopedString m(scope, errorObj->engine()->newString("message"));
+ QV4::ScopedValue v(scope, errorObj->get(m));
+ error.setDescription(v->toQStringNoThrow());
+ } else
+ error.setDescription(exception->toQStringNoThrow());
+ return error;
+}
+
/*!
Returns true if this error is valid, otherwise false.
*/